[Haskell-cafe] RFE: Extensible algebraic user-defined data types?

Keean Schupke k.schupke at imperial.ac.uk
Fri Apr 29 08:17:18 EDT 2005

David Menendez wrote:

>The downside is that a function that might normally be typed "Either A B
>-> C" now will have the type:
>    (HTypeIndexed l,
>     HTypeProxied l,
>     HOccurs (Proxy (Left A)) l,
>     HOccurs (Proxy (Right B)) l) =>
>    TIC l -> C
>But it will accept a TIC (HEither A B) and a TIC (HNEither A B) and any
>other TIC that contains Left A and Right B among its possible values.
>[1] <http://homepages.cwi.nl/~ralf/HList/>
Of course the compiler will infer this type for you. I find it very 
handy to use explicitly typed funtions to compose constraints, thus 
avoiding the need to have big type signatures... something like:

constrainInt :: Int -> Int
constrainInt = id

constrainSomeClass :: SomeClass a => a -> a
constrainSomeClass = id

you can then write:

f i c = someFn (constrainInt i) (constrainSomeClass c)

Where "someFn" has a complicated type like that above...

In this way you can avoid having to specify all the constraints a 
function, and it effectively gives you the same functionality as partial 
type signatures.


More information about the Haskell-Cafe mailing list