[Haskell-cafe] Type families not as useful over functions
John Ky
newhoggy at gmail.com
Thu Feb 12 18:49:19 EST 2009
Hi Miguel,
That's a nice way of writing it.
Thanks,
-John
On Fri, Feb 13, 2009 at 10:42 AM, Miguel Mitrofanov
<miguelimo38 at yandex.ru>wrote:
> What do you need that for?
>
> Can you live with
>
> infixl |$|
> (|$|) :: [a -> r] -> a -> [r]
> fs |$| x = map ($ x) fs
>
> and, instead of "broadcast fs a b" use
>
> fs |$| a |$| b
>
> ?
>
>
> On 13 Feb 2009, at 02:34, 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.
>>
>> In this case, currying is not my friend.
>>
>> Unfortunately this means I'm stuck with numbered function names:
>>
>> bc0 :: [r] -> [r]
>> bc0 rs = rs
>>
>> bc1 :: [a -> r] -> a -> [r]
>> bc1 [] a = []
>> bc1 (r:rs) a = (r a):bc1 rs a
>>
>> bc2 rs a b = rs `bc1` a `bc1` b
>>
>> bc3 rs a b c = rs `bc1` a `bc1` b `bc1` c
>>
>> -- etc
>>
>> Cheers,
>>
>> -John
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090213/4e1bfcf5/attachment.htm
More information about the Haskell-Cafe
mailing list