Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Custom type classes (Chadda? Fouch?)


----------------------------------------------------------------------

Message: 1
Date: Thu, 28 Jan 2016 20:14:21 +0000
From: Chadda? Fouch? <chaddai.fou...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Custom type classes
Message-ID:
        <CANfjZRYY=5WGbJBA9K7tcZh4osfKyB=pdhk45qu3ddj8rbc...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Le mer. 27 janv. 2016 ? 14:29, Guillaume Bouchard <
guillaum.bouchard+hask...@gmail.com> a ?crit :

> However I discovered the `ConstraintKinds` extension which may improve
> the situation.


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...

{-# LANGUAGE ConstraintKinds, TypeFamilies #-}
module ConstrainedFunctor where
import GHC.Exts (Constraint)
import qualified Data.Vector.Unboxed as V

class CFunctor f where
   type FConstraint f x :: Constraint
   type instance FConstraint f x = ()
   cfmap :: (FConstraint f a, FConstraint f b) => (a -> b) -> f a -> f b

instance CFunctor V.Vector where
   type FConstraint V.Vector x = V.Unbox x
   cfmap f v = V.map f v

doubleVector :: V.Vector Int -> V.Vector Int
doubleVector = cfmap (*2)

-- 
Jeda?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160128/17241342/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 91, Issue 36
*****************************************

Reply via email to