Records in Haskell

AntC anthony_clayden at clear.net.nz
Tue Feb 28 11:57:12 CET 2012


J. Garrett Morris <jgmorris <at> cs.pdx.edu> writes:

> 
> Has x f has no semantic content besides type x having an f field; Ord
> has (at least in the programmer's mind, even if the language can't check
> it) meaning beyond the simple presence of a compare function.
> 
>  /g
> 

Note that under both SORF and DORF, there are three arguments to the `Has` 
class. The third is specifically to spec or constrain the type of the result.

A decl:

    data Rec a = Ord a => Rec{ flda :: a }

Expects:

    flda :: (r{ flda :: a }, Ord a) => r -> a

Where the {...} in the constraint is sugar for the Has class. (DORF and SORF 
differ slightly in how that's implemented.)

AntC




More information about the Glasgow-haskell-users mailing list