Created
November 16, 2017 22:31
-
-
Save coot/4e5d3fb4b9ed2f3aa1b3182314534dd8 to your computer and use it in GitHub Desktop.
Type level cofree react router
This file contains hidden or 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
module Type.React.Router where | |
import Control.Monad.Eff (Eff) | |
import Control.Monad.Eff.Console (CONSOLE, log) | |
import Prelude (Unit) | |
import Type.Proxy (Proxy(..)) | |
import Type.Trout (type (:/), Capture, Lit, Named, QueryParam, QueryParams, Sub) | |
type PBool = Proxy Boolean | |
class IsLocation x | |
instance isLocationLit :: IsLocation (Lit v) | |
instance isLocationCapture :: IsLocation (Capture v t) | |
instance isLocationQueryParam :: IsLocation (QueryParam k v) | |
instance isLocationQueryParams :: IsLocation (QueryParams k v) | |
instance isLocationNamed :: (IsLocation l) => IsLocation (Named n l) | |
instance isLocationSub :: (IsLocation l) => IsLocation (Sub v l) | |
data Nil | |
data Cons a as | |
class IsList x | |
instance isListNil :: IsList Nil | |
instance isListCons :: (IsList as) => IsList (Cons a as) | |
list1 :: IsList (Cons Int (Cons String Nil)) => PBool | |
list1 = Proxy | |
notList1 :: IsList (Cons Int (Cons String Int)) => PBool | |
notList1 = Proxy | |
data Leaf a as | |
class IsLeafList x | |
instance isLeafListNil :: IsLeafList Nil | |
instance isLeafListCons :: (IsLocation a, IsList as, IsLeafList as, IsList bs, IsLeafList bs) => IsLeafList (Cons (Leaf a as) bs) | |
llist1 :: IsLeafList (Cons (Leaf (Lit "") (Cons (Leaf (Lit "") Nil) Nil)) Nil) => PBool | |
llist1 = Proxy | |
llist2 :: IsLeafList (Cons (Leaf (Lit "") (Cons (Leaf (Lit "") Nil) Nil)) (Cons (Leaf (Lit "") Nil) Nil)) => PBool | |
llist2 = Proxy | |
class IsRouter x | |
instance isRouterNil :: (IsLocation l) => IsRouter (Leaf l Nil) | |
instance isRouterCons :: (IsLocation l, IsRouter a, IsLeafList as) => IsRouter (Leaf l (Cons a as)) | |
type Router1 = Leaf (Lit "home") (Cons (Leaf ("users" :/ Capture "userId" Int) Nil) Nil) | |
router1 :: IsRouter Router1 => PBool | |
router1 = Proxy | |
type Router2 = Leaf (Lit "home") | |
(Cons | |
(Leaf (Lit "books") | |
(Cons (Leaf (Capture "bookId" Int) Nil) Nil)) | |
(Cons | |
(Leaf (Lit "users") | |
(Cons (Leaf (Capture "userId" Int) Nil) Nil)) | |
Nil)) | |
router2 :: IsRouter Router2 => PBool | |
router2 = Proxy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment