Last active
August 24, 2017 09:29
-
-
Save Icelandjack/c67c26b9b1b6627dc685eff225fe9d2a to your computer and use it in GitHub Desktop.
TODO: Stuff
UndecidableSuperClasses
to implement indexed profunctor lenses
{-# Language UndecidableSuperClasses #-}
class (Unindexed cat ~ Unindexed (Unindexed cat), Indexable index (Unindexed cat)) => Indexable index cat where
type Unindexed cat :: k -> k' -> Type
indexed :: cat a b
-> index -> Unindexed cat a b
instance Indexable index (->) where
type Unindexed (->) = (->)
indexed :: forall a b.
(a -> b)
-> (index -> a -> b)
indexed = const @(a -> b) @index
newtype Indexed i a b = Indexed { runIndexed :: i -> a -> b }
instance index ~ j => Indexable index (Indexed j) where
type Unindexed (Indexed j) = (->)
indexed :: Indexed index a b
-> (index -> a -> b)
indexed = runIndexed
type IndexedTraversal index s t a b = forall p.
(Indexable index p, Traversing p, Traversing (Unindexed p)) =>
p a b -> Unindexed p s t
foo :: IndexedTraversal Int a b [a] [b]
foo = undefined
bar :: IndexedTraversal Int a b [[[[a]]]] [[[[b]]]]
bar = foo.foo.foo.foo
TypeFamilyDependencies
https://github.com/mvr/optics/blob/34080e6cb5ad6017b8eb8cfb8d5402e3e9964874/src/NewTest.hs
class Action (c :: (* -> *) -> Constraint) where
type Wanderer c (a :: *) (b :: *) = (p :: * -> * -> *) | p -> c a b
type Wanderer c a b = LoneWanderer c a b
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
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
Example of my standardising lesser used fixity / operators from