Created
September 19, 2021 04:56
-
-
Save cqfd/2aad2620db047ca91f92d64e742897d7 to your computer and use it in GitHub Desktop.
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 Mappers | |
data Identity a = MkIdentity a | |
Functor Identity where | |
map f (MkIdentity x) = MkIdentity (f x) | |
repapply : Nat -> (a -> a) -> (a -> a) | |
repapply Z f = id | |
repapply (S k) f = f . repapply k f | |
mapND : Functor f => (n: Nat) -> (a -> b) -> (repapply n f $ a) -> (repapply n f $ b) | |
mapND 0 g x = g x | |
mapND 1 g x = map g x | |
mapND (S k) g x = (map . mapND k) g x |
Ooh, whoops, I shouldn't have specified {f=Identity} there, I think you can specify whatever you want! It's just that the type checker can't guess it for you, so you have to manually specify the implicit "forall Functor f." part.
mapND {f=List} 0 (+1) 123
124
Ok! Maybe this is a nicer/smaller version:
module Mappers
repapply : Nat -> (a -> a) -> (a -> a)
repapply Z f = id
repapply (S k) f = f . repapply k f
mapND : Functor f => (n: Nat) -> (a -> b) -> (repapply n f $ a) -> (repapply n f $ b)
mapND 0 g = g
mapND (S k) g = (map . mapND k) g
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then I could do this: