This email was sent to you by someone outside the University.
You should only click on links or attachments if you are certain that the email is genuine and the content is safe.
On Tue, Feb 23, 2021 at 06:14:59PM +0000, CASANOVA Juan wrote:
> module DatatypeContextsExample where
>
> import Data.Map
> import Data.Bifunctor
>
> data Foo t = Foo (Map t t)
>
> instance Functor Foo where
> fmap f (Foo m) = Foo (fromList (fmap (bimap f f) (toList m)))
>
> This does not compile, because I am using toList and fromList, which
> require (Ord t). But I cannot really have Foo be a functor in this
> way without it. The thing is, every time I am going to use it, t is
> actually going to be Ord. But how do I tell Haskell to have this
> constraint?
You say that every time you are going to use it t is actually going to
be Ord, but how does the compiler know that when it comes to type
check fmap? After all, somewhere else you could write
fmap (const getLine) :: Foo t -> Foo (IO String)
and IO String is certainly not Ord.
Tom
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.