Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Falsy lenses #85

Open
jackfirth opened this issue Jul 8, 2015 · 1 comment
Open

Falsy lenses #85

jackfirth opened this issue Jul 8, 2015 · 1 comment
Labels

Comments

@jackfirth
Copy link
Owner

Sometimes it's handy to break the lens laws, just a little bit. Specifically, it might be useful to have a lens that is allowed to "miss" its target, for which viewing returns false and setting is a no-op. There could even be a general function that given a predicate to determine when a lens won't miss, constructs an improper "falsy lens" which obeys the lens laws for all values the predicate returns true for, but for other values always views false and setting does nothing and returns the value unchanged. Currently, the syntax keyword sequence lenses are falsy lenses (but this behavior is undocumented).

@jackfirth jackfirth changed the title Falsy lenses? Falsy lenses Jul 8, 2015
@jackfirth
Copy link
Owner Author

Note: This is a special case of the more general notion of monadic lenses, lenses that operate on monadic values instead of plain values. For a given monad type M, the monadic lens function types are (I think):

view :: Lens s a -> s -> M a
set :: Lens s a -> s -> a -> M s
transform :: Lens s a -> s -> (a -> M a) -> M s

In this case the specific monad is like the Maybe monad, but instead of monadic values being a Just wrapper around the plain value or Nothing, monadic values are plain values (except #f) or #f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant