Created
April 21, 2016 00:44
-
-
Save k0001/5101edb16a67d730446dbdcdaeffbfa9 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
-- | How do I write inductive instances for n-arity functions? Does this have a | |
-- name? How can I add functional dependencies to 'MapLast'? | |
class MapLast s t a b where | |
mapLast :: (a -> b) -> (s -> t) | |
instance MapLast a b a b where | |
mapLast = ($) | |
instance MapLast (z -> a) (z -> b) a b where | |
mapLast = (.) | |
instance MapLast (y -> z -> a) (y -> z -> b) a b where | |
mapLast = (.) . (.) | |
instance MapLast (x -> y -> z -> a) (x -> y -> z -> b) a b where | |
mapLast = (.) . (.) . (.) | |
instance MapLast (w -> x -> y -> z -> a) (w -> x -> y -> z -> b) a b where | |
mapLast = (.) . (.) . (.) . (.) | |
-- Example usage: | |
-- | |
-- > mapLast not True :: Bool | |
-- False | |
-- > mapLast not (\() -> True) () :: Bool | |
-- False | |
-- > mapLast not (\() () -> True) () () :: Bool | |
-- False | |
-- > mapLast not (\() () () -> True) () () () :: Bool | |
-- False | |
-- > mapLast not (\() () () () -> True) () () () () :: Bool | |
-- False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment