git.iko.soy/rowtype-yoga/purescript-native
on 7db07cc help sign in
26 lines 675 B history raw
1module Main where
3import Prelude
5import Control.Monad.Eff (Eff)
6import Control.Monad.Eff.Console (CONSOLE, log)
8class IsStream el s | s -> el where
9 cons :: el -> (Unit -> s) -> s
10 uncons :: s -> { head :: el, tail :: s }
12data Stream a = Stream a (Unit -> Stream a)
14instance streamIsStream :: IsStream a (Stream a) where
15 cons x xs = Stream x xs
16 uncons (Stream x f) = { head: x, tail: f unit }
18test :: forall el s. IsStream el s => s -> s
19test s = case uncons s of
20 { head, tail } -> cons head \_ -> tail
22main :: Eff (console :: CONSOLE) Unit
23main = do
24 let dones :: Stream String
25 dones = cons "Done" \_ -> dones
26 log (uncons (test dones)).head