[Haskell-cafe] Re: Haskell Propaganda

Ben Franksen ben.franksen at online.de
Wed Aug 27 18:56:08 EDT 2008

Brandon S. Allbery KF8NH wrote:
> On 2008 Aug 27, at 16:49, Daniel Fischer wrote:
>> Am Mittwoch, 27. August 2008 22:34 schrieb Aaron Tomb:
>>> When you do use Maybe, you have to explicitly handle the Just and
>>> Nothing cases separately. Pattern matching reminds you that both are
>>> possible. I tend to view fromJust as a function you should only use
>>> if
>>> you're _very_, _very_ sure that the Nothing case is impossible. But,
>>> if so, why are you using a Maybe type in the first place?
>> Good question. Maybe because you use a function which returns a
>> Maybe result
>> but you know in your use case it's always a Just. But then still a
>> case fun args of
>> Just val -> use val
>> Nothing -> error $ LOCATION ++ " Hey, that ought to be impossible! Go
>> investigate!"
>> would be cleaner. If fromJust is more efficient and this code is
>> called many
>> times in your programme, that could count as a reason.
> I have more than once seen a NULL dereference not get caught until
> later (admittedly I think most POSIX-like systems unmap page 0 these
> days; but think of embedded systems or other non-POSIX environments).

Oh yes, embedded systems indeed. We have only recently discovered a subtle
bug in some C code I wrote years ago where I mixed up the order of two
statements. The result was that memory at address zero was overwritten with
a string. Interestingly, we /never/ had any segfaults, exceptions,
whatever, not even broken behavior of any sort. I discovered the problem
only when I explicitly looked at the memory area in question to find out
what the system uses as default interrupt handler (yes, this was VxWorks on
an 68040, and the interrupt vector table is located at zero). In the end I
managed to crash a computer by issuing '1/0' on the shell (apparently the
vector for the division by zero fault handler had been overwritten)...
however, that was after I already knew there was something bad going on.

Note that C compilers are, in principle, free to interpret the value 0, when
compared or assigned to a pointer, as any address they like, so in
principle the C compiler could 're-map' 0 to some never-mapped memory
region. I know of no case where this is done, though.

> even fromJust gives you more of an ability to track the problem down
> in that case.



More information about the Haskell-Cafe mailing list