Can you not define functor like Hughes defines a restricted monad
(section 3 in the paper)...
Keean
Arjun Guha wrote:
One way to do roughly what you want is to pass the dictionary yourself:
>data EqDict a = EqDict {
> leq :: a -> a -> Bool }
>
>data EqList a = EqList (EqDict a) [a]
>
>test :: EqList a -> EqList a -> Bool
>test (EqList dict (a0:as)) (EqList _ (b0:bs)) = (leq dict) a0 b0
This is like the `object-oriented approach' in John Hughes' paper.
Let's switch to the set example in his paper:
> data EqDict a = EqDict { isEq:: a -> a -> Bool }
> data Set a = Set (EqDict a) [a]
So, to make it a functor, as I originally wanted:
> instance Functor Set where
> fmap f (Set dict ls) = Set dict' ls' where
> ls' = nubBy (isEq dict') ls
> dict' = ???
There really isn't a way to define dict' for the resultant Set.
-Arjun
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe