Advertisement
Guest User

Test.hs

a guest
Apr 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE RankNTypes #-}
  2. module Test where
  3.  
  4.   import Prelude hiding (fst, snd)
  5.  
  6.   pair :: a -> b -> (forall c. (a -> b -> c) -> c)
  7.   pair = flip . flip id
  8.  
  9.   fst :: (forall c. (a -> b -> c) -> c) -> a
  10.   fst = ($ const)
  11.  
  12.   snd :: (forall c. (a -> b -> c) -> c) -> b
  13.   snd = ($ const id)
  14.  
  15.   toPair :: (forall c. (a -> b -> c) -> c) -> (a, b)
  16.   toPair p = (fst p, snd p)
  17.  
  18.   fromPair :: (a, b) -> (forall c. (a -> b -> c) -> c)
  19.   fromPair = uncurry pair
  20.  
  21.   nil :: a -> a -> a
  22.   nil = const
  23.  
  24.   -- 寫不出 cons 的 type
  25.   cons :: forall b. a -> ((a -> ??? -> b) -> b) -> ((a -> ??? -> b) -> b)
  26.   cons x xs = \_ cons' -> cons' x xs
  27.  
  28.   -- 再試著寫一遍
  29.   type List a = forall b. (a -> List a -> b) -> b
  30.  
  31.   -- 用 newtype 做出來了可是我想要所有東西都是 function
  32.   newtype List' a = List' {
  33.     unlist :: forall b. (a -> List' a -> b) -> b
  34.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement