Last active
August 29, 2015 14:21
-
-
Save rikvdkleij/6cec00ef1058ed00e935 to your computer and use it in GitHub Desktop.
Purescript Monoid Action exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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