[Haskell-cafe] type families and type signatures

Manuel M T Chakravarty chak at cse.unsw.edu.au
Thu Apr 10 00:52:10 EDT 2008


Lennart Augustsson:
> Let's look at this example from a higher level.
>
> Haskell is a language which allows you to write type signatures for  
> functions, and even encourages you to do it.
> Sometimes you even have to do it.  Any language feature that stops  
> me from writing a type signature is in my opinion broken.
> TFs as implemented in currently implemented ghc stops me from  
> writing type signatures.  They are thus, in my opinion, broken.

The problem of ambiguity is not at all restricted to TFs.  In fact,  
you need neither TFs nor FDs to get the exact same behaviour.  You  
don't even need MPTCs:

> {-# LANGUAGE FlexibleContexts #-}
> module Ambiguity where
>
> class C a
>
> bar :: C (a, b) => b -> b
> bar = id
>
> bar' :: C (a, b) => b -> b
> bar' = bar
>


This gives us

> /Users/chak/Code/haskell/Ambiguity.hs:10:7:
>    Could not deduce (C (a, b)) from the context (C (a1, b))
>      arising from a use of `bar'
>                   at /Users/chak/Code/haskell/Ambiguity.hs:10:7-9
>    Possible fix:
>      add (C (a, b)) to the context of the type signature for `bar''
>      or add an instance declaration for (C (a, b))
>    In the expression: bar
>    In the definition of `bar'': bar' = bar


So, we have this problem as soon as we have flexible contexts and/or  
MPTCs, independent of TFs and FDs.

Manuel



More information about the Haskell-Cafe mailing list