[Haskell-cafe] Haskell Propaganda

Daniel Fischer daniel.is.fischer at web.de
Wed Aug 27 16:49:35 EDT 2008


Am Mittwoch, 27. August 2008 22:34 schrieb Aaron Tomb:
> On Aug 27, 2008, at 12:23 PM, Dan Weston wrote:
> > Huh? Type safety buys you not having to worry about dereferencing
> > stale nonnull pointers (lifetime of reference exceeding lifetime of
> > referent), but nothing about dereferencing null pointers, which are
> > the moral equivalent of Nothing.
>
> What type safety buys you, in my mind, is that Nothing is only a valid
> value for explicit Maybe types. In cases where you don't use Maybe,
> the "null" situation just can't occur. In languages with null
> pointers, any pointer could possibly be null.
>
> 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.
>
> Aaron
Cheers,
Daniel


More information about the Haskell-Cafe mailing list