[Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Stephen Lavelle
Given class MyClass k where type AssociatedType k :: * Is there a way of requiring AssociatedType be of class Eq, say? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Miguel Mitrofanov
{-# LANGUAGE GADTs, TypeFamilies #-} module Assoc where data EqD k where EqD :: Eq k = EqD k class MyClass k where data AssociatedType k :: * evidence :: AssociatedType k - EqD (AssociatedType k) eq :: MyClass k = AssociatedType k - AssociatedType k - Bool -- eq k1 k2 = k1 == k2 --

Re: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Miguel Mitrofanov
Along the same lines: {-# LANGUAGE GADTs, TypeFamilies #-} module Assoc where data EqD k where EqD :: Eq k = EqD k class MyClass k where type AssociatedType k :: * evidence :: k - EqD (AssociatedType k) instance MyClass () where type AssociatedType () = Integer evidence _ = EqD eq

Re: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Roman Leshchinskiy
On 18/12/2009, at 00:37, Stephen Lavelle wrote: Given class MyClass k where type AssociatedType k :: * Is there a way of requiring AssociatedType be of class Eq, say? This works with -XFlexibleContexts: class Eq (AssociatedType k) = MyClass k where type AssociatedType k :: * Roman

Re: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Tom Schrijvers
class MyClass k where type AssociatedType k :: * Is there a way of requiring AssociatedType be of class Eq, say? Have you tried: {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} class Eq (AssociatedType k) = MyClass k where type AssociatedType k :: * ? Cheers, Tom --

Re: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Conor McBride
Hi all On 17 Dec 2009, at 14:22, Tom Schrijvers wrote: class MyClass k where type AssociatedType k :: * Is there a way of requiring AssociatedType be of class Eq, say? Have you tried: {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} class Eq (AssociatedType k) = MyClass k

RE: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Simon Peyton-Jones
of constraints. Simon | -Original Message- | From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-boun...@haskell.org] On | Behalf Of Conor McBride | Sent: 17 December 2009 14:48 | To: Haskell Cafe | Subject: Re: [Haskell-cafe] Restrictions on associated types for classes

Re: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Jacques Carette
: [Haskell-cafe] Restrictions on associated types for classes | | Hi all | | On 17 Dec 2009, at 14:22, Tom Schrijvers wrote: | | class MyClass k where | type AssociatedType k :: * | | Is there a way of requiring AssociatedType be of class Eq, say? | | Have you tried: | | {-# LANGUAGE TypeFamilies

Re: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Conor McBride
On 17 Dec 2009, at 15:31, Simon Peyton-Jones wrote: Hmm. If you have class (Diff (D f)) = Diff f where then if I have f :: Diff f = ... f = e then the constraints available for discharging constraints arising from e are Diff f Diff (D f) Diff (D

RE: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Simon Peyton-Jones
| Hmm. If you have |class (Diff (D f)) = Diff f where | | then if I have | f :: Diff f = ... | f = e | then the constraints available for discharging constraints arising | from e are | Diff f | Diff (D f) | Diff (D (D f)) | Diff (D (D (D f))) | ... | |

Re: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Stephen Lavelle
Ah yes, this is very very very helpful. Thanks : ) Miguel's example is not quite as idiomatic, but...for some reason I find it beguiling nonetheless. On Thu, Dec 17, 2009 at 2:36 PM, Roman Leshchinskiy r...@cse.unsw.edu.au wrote: On 18/12/2009, at 00:37, Stephen Lavelle wrote: Given class

Re: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Martin Sulzmann
The statements class Cl [a] = Cl a and instance Cl a = Cl [a] (I omit the type family constructor in the head for simplicyt) state the same (logical) property: For each Cl t there must exist Cl [t]. Their operational meaning is different under the dictionary-passing translation [1]. The

Re: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Dan Weston
I think the denotational meanings are different. The instance also implies: For each Cl t there must exist a Cl u where u does not unify with [v] for some v. In other words, there must be a ground instance. For the class declaration, the existence of a ground instance can be inferred only by

Re: [Haskell-cafe] Restrictions on associated types for classes

2009-12-17 Thread Dan Weston
Oops, reverse that. The *instance* declaration allows for infinite types, the *class* declaration does not. Dan Weston wrote: I think the denotational meanings are different. The instance also implies: For each Cl t there must exist a Cl u where u does not unify with [v] for some v. In