Type operator constructors for Simple #61

Closed
mgsloan opened this Issue Sep 25, 2012 · 9 comments

Comments

Projects
None yet
2 participants
Collaborator

mgsloan commented Sep 25, 2012

I'm sure that this has been pondered before, but I'd like to open a discussion about it. Simple lenses / traversals / isos are pretty common, so what if they had nice type operators?

These seem good:

type a :-> b = Simple Lens a b
type a :*> b = Simple Traversal a b
type a :<-> b = Simple Iso a b
type a :..> b = Fold a b

I was considering (:%>) for Lens, but decided on (:->) for nicer appearance and consistency with fclabels.

Not sure if I'd need these:

type a :^> b = Simple Getter b
type a :<~ b = Simple Setter b

And these'd be a little silly (but would still save parens!):

type (:@->) a b i = SimpleIndexedLens i a b
-- etc

I dunno about you, but I like these smileys - each variety is just a different nose!

Owner

ekmett commented Sep 25, 2012

I'm somewhat torn about these.

Just writing down the list of issues and thoughts I had had about these before

The nice thing about the existing operators that we do have is that they mostly have a consistent set of semiotics, but that symbology doesn't transfer to these.

This also introduces a new extension into the mix. I don't think we had any type operators in lens before this. ;)

I had also consciously left off infix versions because they pessimized the use of the more correct 4 argument types for many lenses.

That and I was hoping that if I put it off long enough 7.6 would be current enough that I could use aliases that didn't start with :, e.g.

type a <-> b = Simple Iso a b

But, all that said, it looks like the next platform is probably going to ship with 7.4.2, so that is a dead dream.

I can probably be talked into a subset of them. Let me chew on names for a bit. =/

The :-> operator is at least consistent with all the other lens libraries and might help people with the transition.

The Traversal operator there kind of gives me pause though. :=> might be a better "heavy lens" visual for it.

Maybe if we just did Traversal and Lens for now?

Re: SimpleIndexedLens that wouldn't work as an SimpleIndexedLens and its ilk` takes 3 arguments.

Owner

ekmett commented Sep 25, 2012

(and probably Iso)

@ghost ghost assigned ekmett Sep 25, 2012

ekmett added a commit that referenced this issue Sep 25, 2012

ekmett added a commit that referenced this issue Sep 25, 2012

Owner

ekmett commented Sep 25, 2012

We could probably do some kind of evil a:@Int-> b for indexed lenses, using

infixr 0 :@
type family a :@ b
type instance a :@ (i -> c) = SimpleIndexedLens i a c

but it hardly seems worth it and doesn't generalize. ;)

Owner

ekmett commented Sep 25, 2012

Closing this out as 'good enough', but feel free to re-open it.

@ekmett ekmett closed this Sep 25, 2012

Collaborator

mgsloan commented Sep 25, 2012

Yup. I picked operators that start with colon for backwards compatibility
sake. It's unfortunate that it'll be a while before we can assume ghc 7.6
as a bare minimum - it does kinda suck that we either choose operators now
that start with a colon or wait for the new type operators behavior to
become standard.

At once, I really like :=> for traversal, because it's just like lens :->
but with multiple paths. We wouldn't be able to use "->" and "=>" anyway,
for obvious reasons, so this could be a reason to justify the colon. On
the other hand, I can also see people being initially confused about ":=>"
due to its similarity to the builtin "=>".

So, my vote is for having two type operators - ":->" and ":=>"

On Tue, Sep 25, 2012 at 8:23 AM, Edward A. Kmett
notifications@github.comwrote:

Closing this out as 'good enough', but feel free to re-open it.


Reply to this email directly or view it on GitHubhttps://github.com/ekmett/lens/issues/61#issuecomment-8858196.

Owner

ekmett commented Sep 25, 2012

I added :->, :=>, :<-> and pushed out 3.0 (to get zippers into circulation) just a little bit ago.

Collaborator

mgsloan commented Sep 25, 2012

Great!

Thanks for adding those! I think they will make the Lens DSL better,
because I'd like to use the type signatures of the declarations to
determine whether the lens or iso transformation is used. This means I can
have the following:

type a :->: b = a -> b
type a :=>: b = a -> [b]
type a :<->: b = a -> b

Which allows the [d| |] quote to typecheck, while providing information to
TH that distinguishes between lenses and isos. I'm not sure if this is an
approach that's been used before - you can pass in arbitrary configuration
into TH - and make the types work out - by providing the appropriate type
synonyms. Could be an interesting thing to consider in general. It
resolves much of people's problems with using TH for DSLs (obscure errors).

-Michael

On Tue, Sep 25, 2012 at 10:35 AM, Edward A. Kmett
notifications@github.comwrote:

I added :->, :=>, :<-> and pushed out 3.0 (to get zippers into
circulation) just a little bit ago.


Reply to this email directly or view it on GitHubhttps://github.com/ekmett/lens/issues/61#issuecomment-8863004.

Collaborator

mgsloan commented Sep 25, 2012

I'm not sure if it would be good to encourage people to mix the definitions of their lenses, isos, and traversals.

At once, it could make the API really small:

lenq :: DecsQ -> DecsQ
lense, isoe, traversale :: ExpQ -> ExpQ
Owner

ekmett commented Sep 25, 2012

heh, lense is cute.

ekmett added a commit that referenced this issue Nov 6, 2012

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