Created
February 9, 2015 01:44
-
-
Save tonymorris/562eb070ca1feecfd755 to your computer and use it in GitHub Desktop.
Higher-kinds and type-classes are distinct concepts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE RankNTypes #-} | |
module Functor where | |
import Prelude( | |
foldr | |
, (.) | |
, Maybe(Nothing, Just) | |
, maybe | |
) | |
data Functor f = | |
Functor { | |
fmap :: forall a b. (a -> b) -> f a -> f b | |
} | |
instanceList :: | |
Functor [] | |
instanceList = | |
Functor (\f -> foldr ((:) . f) []) | |
instanceMaybe :: | |
Functor Maybe | |
instanceMaybe = | |
Functor (\f -> maybe Nothing (Just . f)) | |
instanceReader :: | |
Functor ((->) t) | |
instanceReader = | |
Functor (.) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment