Skip to content

Instantly share code, notes, and snippets.

@Icelandjack
Last active Aug 24, 2017
Embed
What would you like to do?
TODO: Stuff
@Icelandjack
Copy link
Author

Icelandjack commented Aug 4, 2017

generic-transformation transformer

fmap : (b. Term b => b -> b) -> (b. Term b => b -> b)

https://www.microsoft.com/en-us/research/wp-content/uploads/2003/01/hmap.pdf

6 Refinements and reflections

Having introduced the basics, we pause to reflect on the ideas a little and to make some modest generalisations.

6.1 An aside about types

It is worth noticing that the type of everywhere could equivalently
be written thus:

everywhere :: (forall b. Term b => b -> b) -> (forall a. Term a => a -> a)

by moving the implicit forall a inwards. The nice thing about writing it this way is that it becomes clear that everywhere is a generic-transformation transformer. We might even write this:

type GenericT = forall a. Term a => a -> a
everywhere :: GenericT -> GenericT

The same approach gives a more perspicuous type for everything:

type GenericQ r = forall a. Term a => a -> r
everything :: (r -> r -> r) -> GerericQ r -> GerericQ r

@Icelandjack
Copy link
Author

Icelandjack commented Aug 24, 2017

A tutorial on the universality and expressiveness of fold

uses

fold :: (α  β  β)  β  ([α]  β)

instead of

fold :: (a -> b -> b) -> b -> [a] -> b
-- or
fold :: (a -> b -> b) -> (b -> [a] -> b)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment