Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to non-impredicatively return `Maybe` a lens?

A type like Maybe (Lens' a b) doesn't work because Lens' is under the hood a Rank-2 type, that can't be wrapped in a type constructor without the -XImpredicativeTypes extension (which is not really supported in GHC).

What is thus the best type to give a function that would morally have type

foo :: A -> Maybe (Lens' B C)

A possibility would be to defer the Maybe into a passed continuation

foo' :: ∀ y . A -> (Lens' B C -> y) -> Maybe y

but I don't particularly like that.

like image 261
leftaroundabout Avatar asked Jan 07 '17 15:01

leftaroundabout


1 Answers

This is what the Control.Lens.Reified module is for. It contains newtype wrappers for the lens hierarchy.

foo :: A -> Maybe (ReifiedLens' B C)
like image 113
Benjamin Hodgson Avatar answered Nov 08 '22 16:11

Benjamin Hodgson