Skip to content

Instantly share code, notes, and snippets.

@victorvoid
Last active August 8, 2018 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorvoid/b97fb6880a04eacee2b795596582787c to your computer and use it in GitHub Desktop.
Save victorvoid/b97fb6880a04eacee2b795596582787c to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment