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

Do something with 'fromStrict' and 'toStrict' #168

Open
chshersh opened this issue May 11, 2018 · 5 comments
Open

Do something with 'fromStrict' and 'toStrict' #168

chshersh opened this issue May 11, 2018 · 5 comments
Labels
feature request mistake reexport type:unclear The issue in its current state is not actionable, its type is unclear.
Milestone

Comments

@chshersh
Copy link
Contributor

chshersh commented May 11, 2018

Those functions can be polymorphic.
Also we can add fromLazy and toLazy for convenience.
Also either deprecate toLText or add toLByteString or only add toLByteString and remove fromStrict and toStrict from exports.

Initially was raised by @gromakovsky.

I tried to convert from Text to LByteString with universum and was really confused... The only way to do this is to write:

import qualified Data.ByteString.Lazy as BSL (fromStrict)

t2b :: Text -> LByteString
t2b = BSL.fromStrict . encodeUtf8

Discuss please.

@chshersh chshersh changed the title Make 'fromStrict' and 'toStrict' functions polymorphic Do something with 'fromStrict' and 'toStrict' May 11, 2018
@int-index
Copy link
Member

int-index commented May 11, 2018

class LazyStrict l s | l -> s, s -> l where
  toLazy :: s -> l
  toStrict :: l -> s

fromLazy :: LazyStrict l s => l -> s
fromLazy = toStrict

fromStrict :: LazyStrict l s => s -> l
fromStrict = toLazy

instance LazyStrict L.ByteString S.ByteString
instance LazyStrict L.Text S.Text

something like this?

@chshersh
Copy link
Contributor Author

chshersh commented May 11, 2018

@int-index Yes, this looks quite good to me.

@gromakovsky
Copy link
Member

t2b :: Text -> LByteString
t2b = BSL.fromStrict . encodeUtf8

It's strange that you need to do BSL.fromStrict, because encodeUtf8 is polymorphic and there is instance ConvertUtf8 Text LByteString.

@gromakovsky gromakovsky added the type:unclear The issue in its current state is not actionable, its type is unclear. label Aug 12, 2018
@dcastro
Copy link
Member

dcastro commented Jul 10, 2022

Also either deprecate toLText or add toLByteString or only add toLByteString

I say we deprecate and eventually delete toLText

@dcastro dcastro added this to the v.1.9.0 milestone Jul 10, 2022
@dcastro
Copy link
Member

dcastro commented Sep 10, 2022

Let's also:

  • Delete the re-export of Data.Text.Lazy.toStrict and Data.Text.Lazy.fromStrict from Universum.String.Reexport
  • Remember to update the rules in .hlint.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request mistake reexport type:unclear The issue in its current state is not actionable, its type is unclear.
Projects
None yet
Development

No branches or pull requests

4 participants