Last active
March 8, 2016 15:00
-
-
Save kseo/8db075d9a13143f54dfb to your computer and use it in GitHub Desktop.
The Constraint kind
This file contains 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
-- https://jeltsch.wordpress.com/2013/02/14/the-constraint-kind/ | |
{-# LANGUAGE ConstraintKinds, TypeFamilies #-} | |
import Prelude hiding (Monad (..)) | |
import Data.Set | |
import GHC.Exts (Constraint) | |
setReturn :: el -> Set el | |
setReturn = singleton | |
setBind :: (Ord el, Ord el') => | |
Set el -> (el -> Set el') -> Set el' | |
setBind set1 gen2 = unions (Prelude.map gen2 (toList set1)) | |
class Monad mon where | |
type Object mon val :: Constraint | |
type Object mon val = () | |
return :: Object mon val => | |
val -> mon val | |
(>>=) :: (Object mon val, Object mon val') => | |
mon val -> (val -> mon val') -> mon val' | |
instance Monad Set where | |
type Object Set el = Ord el | |
return = setReturn | |
(>>=) = setBind |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment