[Haskell-beginners] Question about constraints, signatures

Philippe Sismondi psismondi at arqux.com
Mon May 9 22:47:28 CEST 2011


On 2011-05-09, at 4:04 AM, David Virebayre wrote:

> 2011/5/8 Philippe Sismondi <psismondi at arqux.com>:
> 
>> On 2011-05-06, at 12:12 PM, Brent Yorgey wrote:
> 
>>> On Fri, May 06, 2011 at 11:34:47AM -0400, Philippe Sismondi wrote:
>>>> I am trying to understand the Typeclassopedia article by Brent Yorgey in Monad.Reader. I am simultaneously working my way through Real World Haskell, so I may be doing things a bit out of order.
> 
>>>> I (more or less) understand that types and typeclasses are not the same.
>>>> But it seems to me that they do conflate in a way, if we think of types as defined by functions on them.
>>>> So why should we not be able to write:
> 
>>>> f ::  Num d -> String -> Int
> 
> You can have multiple class constraints, so it's not clear how you
> would write them using your syntax; how would you write :
> 
> f :: (Eq d, Ord d) => d -> String -> Int ?
> 
> Also, you only have to tell the class constraint once, with your syntax
> 
> g :: (Num d) => d -> d -> d
> 
> would become:
> 
> g :: Num d -> Num d -> Num d
> 
> but that syntax lets you write nonsense :
> 
> h :: Num d -> Eq d -> Ord d
> 
> 
> David.

David:

Thanks for your input. As I have quite a distance to go with Haskell, I shall take all these comments under advisement.

- Phil -


More information about the Beginners mailing list