Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.