Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE RankNTypes #-}
- module Test where
- import Prelude hiding (fst, snd)
- pair :: a -> b -> (forall c. (a -> b -> c) -> c)
- pair = flip . flip id
- fst :: (forall c. (a -> b -> c) -> c) -> a
- fst = ($ const)
- snd :: (forall c. (a -> b -> c) -> c) -> b
- snd = ($ const id)
- toPair :: (forall c. (a -> b -> c) -> c) -> (a, b)
- toPair p = (fst p, snd p)
- fromPair :: (a, b) -> (forall c. (a -> b -> c) -> c)
- fromPair = uncurry pair
- nil :: a -> a -> a
- nil = const
- -- 寫不出 cons 的 type
- cons :: forall b. a -> ((a -> ??? -> b) -> b) -> ((a -> ??? -> b) -> b)
- cons x xs = \_ cons' -> cons' x xs
- -- 再試著寫一遍
- type List a = forall b. (a -> List a -> b) -> b
- -- 用 newtype 做出來了可是我想要所有東西都是 function
- newtype List' a = List' {
- unlist :: forall b. (a -> List' a -> b) -> b
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement