<div dir="ltr"><div class="gmail_quote"><div dir="ltr">Le mer. 27 janv. 2016 à 14:29, Guillaume Bouchard <<a href="mailto:guillaum.bouchard%2Bhaskell@gmail.com">guillaum.bouchard+haskell@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
However I discovered the `ConstraintKinds` extension which may improve<br>
the situation.</blockquote><div><br></div><div>It does, it is in fact quite easy in modern Haskell to write a typeclass analogue to a functor but which may have further constraints on the types contained. But it won't be the historic "Functor" typeclass which is ubiquitous in the Haskell packages...<br><br>{-# LANGUAGE ConstraintKinds, TypeFamilies #-}<br>module ConstrainedFunctor where<br>import GHC.Exts (Constraint)<br>import qualified Data.Vector.Unboxed as V<br><br>class CFunctor f where<br> type FConstraint f x :: Constraint<br> type instance FConstraint f x = ()<br> cfmap :: (FConstraint f a, FConstraint f b) => (a -> b) -> f a -> f b<br><br>instance CFunctor V.Vector where<br> type FConstraint V.Vector x = V.Unbox x<br> cfmap f v = V.map f v<br><br>doubleVector :: V.Vector Int -> V.Vector Int<br>doubleVector = cfmap (*2)<br><br>-- <br></div><div>Jedaï<br></div></div></div>