[Haskell-cafe] Trapped by the Monads

Mark Carter mcturra2000 at yahoo.co.uk
Tue Sep 20 16:46:06 EDT 2005


Lennart Augustsson 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.)

Yes, I didn't mean to imply that Haskell had got its ideas fundamentally 
wrong. I think that the main thrust of the argument is that in something 
like C, hybrid variables make it easy for a programmer to inadvertently 
use them wrongly, as opposed to just be lazy. I suppose there's some 
element of debate on the matter: for example, what C programmer doesn't 
honestly know that memory allocation can fail. And for an unfamiliar 
function, why doesn't the programmer read the documentation to find out 
what constitutes valid and invalid return values.

OTOH, I think Charles Moore is quoted as saying that if he want to add 1 
to the letter A, then he didn't want the programming language to stop 
him. Which is quite a contrast to Haskell and its notions on safety. I'm 
not flamebaiting, you understand, I'm just pointing out the various 
viewpoints to the argument.



		
___________________________________________________________ 
How much free photo storage do you get? Store your holiday 
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com


More information about the Haskell-Cafe mailing list