Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Oliver Bandel <oliver@first.in-berlin.de>
To: Michal Moskal <malekith@pld-linux.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Some/None
Date: Wed, 24 Apr 2002 16:23:34 +0200 (MET DST)	[thread overview]
Message-ID: <Pine.LNX.3.95.1020424161406.846D-100000@first.in-berlin.de> (raw)
In-Reply-To: <20020424133110.GA10571@ep09.kernel.pl>

Hello,

On Wed, 24 Apr 2002, Michal Moskal wrote:

> On Wed, Apr 24, 2002 at 02:48:41PM +0200, Oliver Bandel wrote:
> > How are Some/None defined, what are they good for?
> 
> This is similar in idea to NULL pointer in C. E.g. struct foo *ptr
> is NULL iff ptr cannot be assigned any reasonable value of type foo.
> You can use 'foo option' in ML the same way -- x : foo option is
> None if no foo is the right value for x.
> 
> > A small, simple example will help a lot.
> 
> let head x =
>   match x with
>   | h::_ -> Some h
>   | [] -> None
> 
> Here if no reasoable value of the head of the list can be returned
> 'None' is used.

OK, In had typed it into the toplevel and as
expected, it does not give back a pure type
(like int's or strings).
It gives back
 None    
     or
 Some 8
     or
 Some "hello"

If aplicated to an empty list, a list of
integers or a list of strings.

Is this really a commeon way of programming?
If I work on a list of integers or a list of
strings, does it really have advantages to
use such a type?

> 
> I personally use mutable fields in records of option type. They are
> initially None, and are filled at some step of computations.


Hmhh, ok. I now see the similarity to NULL in C.

> However
> this is non-functional/ugly/etc ;)

Pattern match itself is not functional.

How can such things be expressed in a functional
way? (Maybe I have to try it in Haskell, it's
constraints to be functional are much stronger;
when using Ocaml it seems to be that very often
the imperative style creeps in - even unconsciously).

Ciao,
   Oliver

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-04-24 15:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-24 12:48 Oliver Bandel
2002-04-24 13:31 ` Michal Moskal
2002-04-24 14:23   ` Oliver Bandel [this message]
2002-04-24 15:43     ` Samuel Lacas
2002-04-24 13:41 ` Markus Mottl
2002-04-24 15:59   ` Oliver Bandel
2002-04-24 13:50 ` Oliver Bandel
2002-04-24 14:08   ` Xavier Leroy
2002-04-24 19:19     ` Oliver Bandel
2002-04-24 14:28   ` Remi VANICAT
2002-04-24 14:55   ` John Max Skaller
2002-04-24 16:49     ` Oliver Bandel
2002-04-25  1:46       ` John Max Skaller
2002-04-25 12:13         ` Oliver Bandel
2002-04-25 12:34           ` Markus Mottl
2002-04-25 12:53             ` Jérôme Marant
2002-04-25 13:13               ` Markus Mottl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.3.95.1020424161406.846D-100000@first.in-berlin.de \
    --to=oliver@first.in-berlin.de \
    --cc=caml-list@inria.fr \
    --cc=malekith@pld-linux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox