Created
March 15, 2016 05:01
-
-
Save nponeccop/b64f5f80b685915e3580 to your computer and use it in GitHub Desktop.
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
{-# LANGUAGE Rank2Types #-} | |
module Main where | |
-- data Cont r a = Cont { runCont :: (a -> r) -> r } | |
import Control.Monad.Cont | |
calculateLength :: [a] -> Cont r Int | |
calculateLength l = return (length l) | |
type ContS r a = (a -> r) -> r | |
type ContH a = forall r . (a -> r) -> r | |
-- iff :: Bool -> Cont () a -> Cont () a -> Cont a | |
iff :: Bool -> ContH a -> ContH a -> ContH a | |
iff b k1 k2 k = if b | |
then k1 k | |
else k2 k | |
returnH :: a -> ContH a | |
returnH = flip ($) | |
succK, predK :: Int -> ContS a Int | |
succH :: Int -> ContH Int | |
succH x k = k (succ x) | |
succK x k = k (succ x) | |
predK x k = k (pred x) | |
succM, predM :: Int -> Cont a Int | |
succM x = return (succ x) | |
predM x = return (pred x) | |
true, false :: a -> a -> a | |
true x y = x | |
false x y = y | |
type BoolC = forall a . a -> a -> a | |
ifc :: BoolC -> a -> a -> a | |
ifc f x y = f x y | |
ifcK :: BoolC -> ContH a -> ContH a -> ContH a | |
ifcK b k1 k2 = \k -> ifc b (k1 k) (k2 k) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment