[Haskell-cafe] Trapped by the Monads
Michael Walter
michael.walter at gmail.com
Tue Sep 20 16:57:33 EDT 2005
Compare:
int *p=...;
int x=*p;
and:
let
p = ...
Just x = p
So actually, there is few difference between dereferencing a pointer
without checking for 0, and extracting the Maybe value without
handling Nothing, apart from that it leads to undefined behavior in C
which in fact isn't really a point against "hybrid variables".
On 9/20/05, Lennart Augustsson <lennart at augustsson.net> wrote:
> Mark Carter wrote:
> > The typical example in C is:
> > mem = malloc(1024)
> > Malloc returns 0 to indicate that memory cannot be allocated, or a
> > memory address if it can. The variable mem is a so-called hybrid
> > variable; it crunches together 2 different concepts: a boolean value
> > (could I allocate memory?) and an address value (what is the address
> > where I can find my allocated memory).
> >
> > It's considered a bad idea because it makes it easy for programmers to
> > use the value inappropriately - witness the number of programmers who
> > pass in 0 as a memory location.
>
> This is a bad idea in C, because you cannot force programmers to test
> the return value properly.
>
> The Maybe type in Haskell is a good idea, because you must test the
> a Maybe value to extract the real value. (Using the Maybe monad this
> can be hidden.)
>
> -- Lennart
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list