<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Tom,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Yes I realize that, but what I am expecting, I guess, is for the type checker to tell me (or anyone who tried to use it) that Foo (IO String) makes no sense, because Foo is always applied to something with Ord. That the very concept of the type Foo (IO String)
 itself does not type check.<br>
<br>
I realize the answer might be that this is impossible with current Haskell, but then a) Is there any fundamental reason why it is impossible, like it would never be possible to do this, or is it just a feature that is not clear how to implement in GHC? and
 b) The basic problem that I have: Implementing an fmap for something like Foo. Can I really just not do it in any way or shape, with any form of workaround?<br>
<br>
So far what I have been doing with situation similar to this is to just create the function fmap_foo that does what fmap does, with the proper constraints. But this is not enough when later on I want to use some other function that requires Foo to actually
 implement Functor. It would basically mean I have to re-implement all the structure while adding all the additional "Ord" constraints.<br>
<br>
Thanks,<br>
Juan.<br>
<br>
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Haskell-Cafe <haskell-cafe-bounces@haskell.org> on behalf of Tom Ellis <tom-lists-haskell-cafe-2017@jaguarpaw.co.uk><br>
<b>Sent:</b> 23 February 2021 18:29<br>
<b>To:</b> haskell-cafe@haskell.org <haskell-cafe@haskell.org><br>
<b>Subject:</b> Re: [Haskell-cafe] DatatypeContexts / alternative</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">This email was sent to you by someone outside the University.<br>
You should only click on links or attachments if you are certain that the email is genuine and the content is safe.<br>
<br>
On Tue, Feb 23, 2021 at 06:14:59PM +0000, CASANOVA Juan wrote:<br>
> module DatatypeContextsExample where<br>
><br>
> import Data.Map<br>
> import Data.Bifunctor<br>
><br>
> data Foo t = Foo (Map t t)<br>
><br>
> instance Functor Foo where<br>
>     fmap f (Foo m) = Foo (fromList (fmap (bimap f f) (toList m)))<br>
><br>
> This does not compile, because I am using toList and fromList, which<br>
> require (Ord t). But I cannot really have Foo be a functor in this<br>
> way without it. The thing is, every time I am going to use it, t is<br>
> actually going to be Ord. But how do I tell Haskell to have this<br>
> constraint?<br>
<br>
You say that every time you are going to use it t is actually going to<br>
be Ord, but how does the compiler know that when it comes to type<br>
check fmap?  After all, somewhere else you could write<br>
<br>
    fmap (const getLine) :: Foo t -> Foo (IO String)<br>
<br>
and  IO String  is certainly not Ord.<br>
<br>
Tom<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br>
</div>
</span></font></div>
The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. Is e buidheann carthannais a th’ ann an Oilthigh Dhùn Èideann, clàraichte an Alba, àireamh clàraidh SC005336.
</body>
</html>