Skip to content

Instantly share code, notes, and snippets.

@rikvdkleij
Last active August 29, 2015 14:21
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 rikvdkleij/6cec00ef1058ed00e935 to your computer and use it in GitHub Desktop.
Save rikvdkleij/6cec00ef1058ed00e935 to your computer and use it in GitHub Desktop.
Purescript Monoid Action exercise
module Data.Action where
import Data.Array
import Data.Monoid
class (Monoid m) <= Action m a where
act :: m -> a -> a
instance numberSemigroup :: Semigroup Number where
(<>) x y = x * y
instance numberMonoid :: Monoid Number where
mempty = 1
instance repeatAction :: Action Number String where
act 0 _ = ""
act n s = s ++ act (n - 1) s
instance arrayAction :: (Monoid m, Action m a) => Action m [a] where
act x ys = go x ys
where
go _ [] = []
go x (z : zs) = (act x z) : (go x zs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment