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

Generalize types of lenses and isos #12

Open
Gabriella439 opened this issue Jun 15, 2014 · 3 comments
Open

Generalize types of lenses and isos #12

Gabriella439 opened this issue Jun 15, 2014 · 3 comments

Comments

@Gabriella439
Copy link
Contributor

As you probably know, these lenses and isos actually have more general types using four type parameters instead of two. Would it be possible to generalize these all to the four type parameter versions? I often find myself wanting the more general types.

An example of this is a "head" utility for streaming text. I'd like to write this:

over (utf8 . lines) (takes 10)

... but this only type-checks if you use the more general type for those two lenses.

I plan on implementing a similar change for pipes-bytestring.

@Gabriella439
Copy link
Contributor Author

I've updated pipes-bytestring to show what I mean, and you can find the example of the updated lines function here:

https://github.com/Gabriel439/Haskell-Pipes-ByteString-Library/blob/master/src/Pipes/ByteString.hs#L970

I can write up the changes to pipes-text for you, but I just wanted to see if you were okay with this change first.

@michaelt
Copy link
Owner

There will be more cleanup needed, but with the changes I still can't get

over (utf8 . lines) (takes 10)

to typecheck:

>>> :t over (utf8 . lines)
over (utf8 . lines)
  :: Monad m =>
     (FreeT (Producer Text m) m (Producer ByteString m x)
      -> FreeT (Producer Text m) m (Producer ByteString m y))
     -> Producer ByteString m x -> Producer ByteString m y

>>> :t takes 10
takes 10 :: (Functor f, Monad m) => FreeT f m () -> FreeT f m ()

>>> :t over (utf8 . lines) (takes 10)

<interactive>:1:22:
    Couldn't match type ‘()’ with ‘Pipes.Proxy X () () ByteString m x’
    Expected type: FreeT (Producer Text m) m (Producer ByteString m x)
                   -> FreeT (Producer Text m) m (Producer ByteString m y)
      Actual type: FreeT (Producer Text m) m ()
                   -> FreeT (Producer Text m) m ()
    In the second argument of ‘over’, namely ‘(takes 10)’
    In the expression: over (utf8 . lines) (takes 10)

@Gabriella439
Copy link
Contributor Author

Oh yeah, you're right. It doesn't solve that particular problem. I feel sheepish. -.-

Then put this on hold until I come up with a more compelling use case for this.

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

No branches or pull requests

2 participants