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
{-# 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 --
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
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
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
--
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
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
: [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
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
| 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)))
| ...
|
|
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
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
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
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
14 matches
Mail list logo