Last active
March 20, 2017 18:51
-
-
Save fizruk/a73cd387bdb46c2857157afb7ab86370 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Data.Monoid | |
newtype F a b = F (a -> b) | |
deriving (Functor) | |
instance Monoid b => Monoid (F a b) where | |
mempty = F mempty | |
mappend (F f) (F g) = F (f <> g) | |
instance (Bounded a, Enum a) => Foldable (F a) where | |
foldMap f (F g) = foldMap (f . g) [minBound..maxBound] | |
instance (Bounded a, Enum a) => Traversable (F a) where | |
traverse f (F g) = fmap (F . index) (traverse (f . g) [minBound..maxBound]) | |
where | |
index xs x = xs !! fromEnum x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment