Code Monkey home page Code Monkey logo

Comments (11)

DanBurton avatar DanBurton commented on June 15, 2024

Re-exporting fromString sounds like a great idea to me.

from basic-prelude.

singpolyma avatar singpolyma commented on June 15, 2024

fromString sounds like the right solution, though it always scares me because of broken instances like the Bytestring.Char8 one.

from basic-prelude.

nikita-volkov avatar nikita-volkov commented on June 15, 2024

Alternatively I thought it could be nice to have a custom ToText typeclass with a toText function and instances for all the exported types for which it makes sense. This way besides solving the current issue it would make it easy to convert to text from all kinds of ByteString and etc., which in my experience is a very common problem.

from basic-prelude.

singpolyma avatar singpolyma commented on June 15, 2024

http://hackage.haskell.org/packages/archive/text-format/0.3.0.8/doc/html/Data-Text-Buildable.html

from basic-prelude.

singpolyma avatar singpolyma commented on June 15, 2024

@nikita-volkov BTW, you cannot safely convert from ByteString to Text in the same way you can convert other types to Text, because to convert ByteString you must specify an encoding.

from basic-prelude.

snoyberg avatar snoyberg commented on June 15, 2024

+1 for including fromString, and possibly IsString as well. But I don't like the idea of adding any custom typeclasses to basic-prelude: I think the goal of basic-prelude should be, as much as possible, to reuse existing typeclass infrastructure, not create new, incompatible typeclasses.

from basic-prelude.

nikita-volkov avatar nikita-volkov commented on June 15, 2024

@singpolyma Yes, but I think decodeUtf8 would have covered most cases, since UTF8 is already a de facto standard. In other situations people are always free to make specific imports.

@snoyberg Yes, it's good that you have some groundrules behind the design of the package. What could be done is creating a third version of Prelude on top of BasicPrelude, which won't have these restrictions. Of course it wouldn't make much sense to do such thing just for a single class right now, so I just want you to consider it as a possiblity for future, when some similar requirements arise for other features.

from basic-prelude.

snoyberg avatar snoyberg commented on June 15, 2024

I'd say that classy-prelude is the place for that kind of stuff for me. But for people looking for a non-classy approach, there should certainly be another package available. And that's one of the main goals of basic-prelude: making it easy to create new preludes.

For the record, I really dislike the partial nature of decodeUtf8. I consider it to be a major bug in text actually. (Though it's the only misfeature I know of there.)

from basic-prelude.

nikita-volkov avatar nikita-volkov commented on June 15, 2024

Okay.

Partial nature - what's that?

from basic-prelude.

snoyberg avatar snoyberg commented on June 15, 2024

The following program:

{-# LANGUAGE OverloadedStrings #-}
import Data.Text ()
import Data.Text.Encoding
import Data.ByteString.Char8 ()

main = print $ decodeUtf8 "\192"

produces:

Cannot decode byte '\xc0': Data.Text.Encoding.decodeUtf8: Invalid UTF-8 stream

from basic-prelude.

nikita-volkov avatar nikita-volkov commented on June 15, 2024

Oh.. Okay. Thank you

from basic-prelude.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.