git.iko.soy/rowtype-yoga/purescript-native
on 67bfcd5 help sign in
41 lines 1.3 kB history raw
1-- Taken from https://github.com/LiamGoodacre/purescript-fun-with-fundeps
3module Main where
5import Control.Monad.Eff.Console (log)
7-- Nat : Type
8data Z
9data S n
11type S2 n = S (S n)
12type S3 n = S (S2 n)
13type S4 n = S (S3 n)
14type S5 n = S (S4 n)
15type S15 n = S5 (S5 (S5 n))
17class NatPlus l r o | l r -> o
18instance natPlusZ :: NatPlus Z r r
19instance natPlusS :: (NatPlus l r o) => NatPlus (S l) r (S o)
21class NatMult l r o | l r -> o
22instance natMultZ :: NatMult Z n Z
23instance natMultS :: (NatMult m n r, NatPlus n r s) => NatMult (S m) n s
25-- Foreign Vect
26foreign import data FVect :: * -> * -> *
27foreign import fnil :: forall e. FVect Z e
28foreign import fcons :: forall n e. e -> FVect n e -> FVect (S n) e
29foreign import fappend :: forall l r o e. (NatPlus l r o) => FVect l e -> FVect r e -> FVect o e
30foreign import fflatten :: forall f s t o. (NatMult f s o) => FVect f (FVect s t) -> FVect o t
31foreign import ftoArray :: forall n e. FVect n e -> Array e
33-- should be able to figure these out
34fsingleton x = fcons x fnil
35fexample = fcons 1 (fsingleton 2) `fappend` fsingleton 3 `fappend` fcons 4 (fsingleton 5)
36fexample2 = fexample `fappend` fexample `fappend` fexample
37fexample3 = fsingleton fexample `fappend` fsingleton fexample `fappend` fsingleton fexample
39fexample4 = fflatten fexample3
41main = log "Done"