Skip to content

Instantly share code, notes, and snippets.

@tydeu
Created January 4, 2020 03:08
Show Gist options
  • Save tydeu/415d3401e618eb7c2f1fbb43b3dee7c4 to your computer and use it in GitHub Desktop.
Save tydeu/415d3401e618eb7c2f1fbb43b3dee7c4 to your computer and use it in GitHub Desktop.
{-# LANGUAGE RankNTypes #-}
module Cont where
import Data.Coerce
import Data.Function
import Control.Applicative
import Control.Monad
newtype Cont a = Cont { runCont :: forall r. (a -> r) -> r }
cont :: a -> Cont a
cont a = Cont ($ a)
instance Functor Cont where
fmap = liftM
instance Applicative Cont where
pure = cont
liftA2 = liftM2
(*>) = (>>)
(<*) = flip (>>)
instance Monad Cont where
(>>=) = runCont
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment