[Haskell-cafe] Type families not as useful over functions

John Ky newhoggy at gmail.com
Thu Feb 12 19:15:32 EST 2009


Hi Johnaton,

Ah yes.  That makes sense.  Is there a way to define type r to be all types
except functions?

-John

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
>
> jcc
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090213/23be026d/attachment.htm


More information about the Haskell-Cafe mailing list