[Haskell-cafe] Haskell Propeganda

Alexander Dunlap alexander.dunlap at gmail.com
Thu Aug 28 19:24:04 EDT 2008


On Thu, 28 Aug 2008, Brandon S. Allbery KF8NH wrote:

> On 2008 Aug 28, at 13:21, Tim Newsham wrote:
>>> GNU ld supports "pragmas" which cause the use of certain functions to 
>>> output warnings at link time (try compiling a C program that uses gets()). 
>>> It occurs to me that this, either in compiler or linker, would be a nice 
>>> thing for ghc to do when using fromJust or other partial functions.
>> 
>> would you include all partial functions in this, such as head?
>
>
> I'd like to, but IMO head is a little more acceptable because lists aren't 
> binary like Maybe.  fromJust really is the Haskell equivalent of 
> dereferencing a pointer without checking if it's NULL, aside from being more 
> reliably detectable.
>
> -- 
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
> system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
> electrical and computer engineering, carnegie mellon university    KF8NH

Tools like Neil Mitchell's Catch can do more sophisticated checking, as long as your program can be compiled by YHC. Sometimes fromJust can be quite useful, though, especially in tandem with isJust. For example,

> prop_foobar :: SomeType -> Property
> prop_foobar x
>   = isJust (someTypeToMaybe x) ==> fromJust x == expectedResult

Alex


More information about the Haskell-Cafe mailing list