<div dir="ltr">It is impossible.<div><br></div><div>You can make a new functor class using contraint kinds that allows what you want. There is probably a package out there already that does!</div><div><br></div><div><a href="http://www.cl.cam.ac.uk/~dao29/publ/constraint-families.pdf">http://www.cl.cam.ac.uk/~dao29/publ/constraint-families.pdf</a><br></div><div><br></div><div>Sections 2.2 and 5.1 have the relevant stuff. I realise this is a bit err, dense for the beginners list. There are probably better references out there.</div><div><br></div><div>Ben</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, 4 Jan 2016 at 14:30 martin <<a href="mailto:martin.drautzburg@web.de">martin.drautzburg@web.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am 01/04/2016 um 11:45 AM schrieb Imants Cekusins:<br>
>> a newtype for ordered lists<br>
><br>
> why not:<br>
> newtype Ordlist a = Ordlist [a]<br>
<br>
All nice and dandy, but at first you already need an Ord constraint for your smart constructor<br>
<br>
-- and a ctor:<br>
ordList::(Ord a) => [a]-> OrdList a<br>
ordList = OrdList . sort<br>
<br>
but this is still not the main problem. When you try to define a Functor instance, you'd be tempted to do this (at least<br>
I was):<br>
<br>
instance Functor OrdList where<br>
        fmap f (OrdList xs) = OrdList $ sort $ map f xs<br>
<br>
but you can't do this, because of: "No instance for (Ord b) arising from a use of ‘sort’", where b is the return type of<br>
f :: (a->b). This does make sense, the function has to return something which can be sorted.<br>
<br>
So my question is: is it impossible to write a functor instance for ordered lists? It appears so, because a Functor does<br>
not impose any constraints of f. But my knowledge is quite limited and maybe a well-set class constraint can fix things.<br>
<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>