-- FormalZ -- ------- -- Demonstration of some classic FP data structures. module formalz -- TODO interface should declare a partially implemented module, -- parameterized by a single type varialbe of any kind. -- TODO `=` syntax allows for same line, single def intreface interface functor f = map: f a -> (a -> b) -> f b -- TODO parameterized implementations must share the exact -- namespace of the interface - eg, in another module, this would -- would be `module formalz.functor List` module functor List = map = list.map interface monad m (>>=): m a -> (a -> m b) -> m b return: a -> m a interface monad.run m -- TODO interfaces can open modules also, which act in the type system -- as constraints. The constraints themselves are not expressable in a -- type signature - the fact that mond.extras only works on `m` when -- there is a `module monad m` somewhere in existence. Error -- messages will need to show the dependency stack. I have a -- philosophical justification for this. -- TODO `import` should work like `open`, but also create aliases. open monad m run: m a -> a module monad List (>>=) x g = concat_map g x return x = [:x] (1..3 >>= λx = [: x, x + 1, x + 2 ]) == [:1,2,3,2,3,4,3,4,5] -- TODO allow joining of interface definitions with `&` for clarity module monad JS & monad.extras JS -- TODO inline definitions - maybe should have decorator -- syntax for this? inline (>>=) x f = x >>= f return x = return x run f = `undefined` -- Note: beacuse `do!` is implemented in terms of run, -- there is no way to actually write this function. -- TODO allow invisible modules like this maybe? module _ -- *TODO* allow local module open `let open monad List`, or force sig -- TODO allow private modules private module utils open formalz.monad List [:1,2,3,2,3,4,3,4,5] == do x <- [:1, 2, 3] [:x, x + 1, x + 2] -- TODO private definitions (only needs to be implemented in type checker) private zzz = 1 -- TODO tail call elimination -- TODO `in` keyword for same line let expressions? let f x = if x > 0 then f (x - 1) else true in f 50000