[Haskell-beginners] Functor instance for ordered lists

martin martin.drautzburg at web.de
Mon Jan 4 09:57:27 UTC 2016


Hello all,

Data.List.Ordered is just a bunch of functions operating on ordinary Lists. Fmapping a function over an ordered list has
the potential of blowing the ordering.

Would it be possible to define a newtype for ordered lists where the order is guaranteed to be maintained? The functor
instance then may have to re-order the elements.

The problem I see is that

data Ordlist a = ...

would certainly require an Ord constraint on a, but where would I put it? I can put it on all the functions manipulating
OrdLists, but I still wouldn't know how to define a functor instance, because a Functor a does not require Ord a.


More information about the Beginners mailing list