[Haskell-cafe] Type families not as useful over functions
newhoggy at gmail.com
Thu Feb 12 19:15:32 EST 2009
Ah yes. That makes sense. Is there a way to define type r to be all types
On Fri, Feb 13, 2009 at 10:44 AM, Jonathan Cast
<jonathanccast at fastmail.fm>wrote:
> On Fri, 2009-02-13 at 10:34 +1100, John Ky wrote:
> > Hi Haskell Cafe,
> > I tried using type families over functions, but when I try it
> > complains that the two lines marked conflict with each other.
> > class Broadcast a where
> > type Return a
> > broadcast :: a -> Return a
> > instance Broadcast [a -> r] where
> > type Return [a -> r] = a -> [r] -- Conflict!
> > broadcast fs a = 
> > instance Broadcast [a -> b -> r] where
> > type Return [a -> b -> r] = a -> b -> [r] -- Conflict!
> > broadcast fs a b = 
> > Given that in Haskell, every function of n+1 arguments is also a
> > function of n arguments, this is likely the cause of the conflict.
> This solution is somewhat in-extensible in the ultimate result type (r,
> in your code); if the number of types r can take on is limited, it
> should work well, though. For expository purposes, I assume that r is
> always Int:
> -- | Conal Elliot's semantic editor combinator argument
> argument :: (a -> a') -> (a -> b) -> (a' -> b)
> argument f g = g . f
> class Broadcast a where
> type Return a
> broadcast :: [a] -> Return a
> instance Broadcast Int where
> type Return Int = [Int]
> broadcast ns = ns
> instance Broadcast r => Broadcast (a -> r) where
> type Return (a -> r) = a -> Return r
> broadcast fs x = (map.argument) (const x) fs
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe