|
module Main where |
|
|
|
import Prelude |
|
|
|
import Control.Comonad (class Comonad, class Extend, extract) |
|
import Control.Monad.Eff.Console (logShow) |
|
|
|
-- Javascript - const Functor = x => ({}) |
|
newtype Box a = Box a |
|
-- Javascript - map: f => (f(x)) |
|
instance functorBox :: Functor Box where |
|
map f (Box x) = Box (f x) |
|
-- Javascript - fold: f => f(x) |
|
instance extendBox :: Extend Box where |
|
extend f m = Box (f m) |
|
instance comonadBox :: Comonad Box where |
|
extract (Box x) = x |
|
|
|
app :: Int -> Int |
|
app n = |
|
Box n # |
|
map (\n -> n * 2) # |
|
map (\n -> n + 1) # |
|
extract |
|
|
|
|
|
main = do |
|
logShow $ app $ 10 |
|
-- 21 |