Giter Site home page Giter Site logo

No Read instance about currency-convert HOT 9 CLOSED

Gurkenglas avatar Gurkenglas commented on August 15, 2024
No Read instance

from currency-convert.

Comments (9)

tuomas56 avatar tuomas56 commented on August 15, 2024

Thanks, I have moved the existing Show instance to the pprint function and added derived Show and Read instances. Fixed in latest commit.

from currency-convert.

Gurkenglas avatar Gurkenglas commented on August 15, 2024

Aw, this loses the symbol. Are you sure you want the output to be Currency 123 rather than usd 123? I mean this looks like a Currency is supposed to be an equivalence class of sums of money in different currencies that are worth the same - so then read . show should land you in the same equivalent class regardless of which read and show are used, right?

from currency-convert.

tuomas56 avatar tuomas56 commented on August 15, 2024

Well, because of the way symbol works it's actually not possible to have a
read implementation that preserves it, you can only convert from symbol to
string AFAIK, not the other way round.

On 16 Aug 2016 01:58, "Gurkenglas" [email protected] wrote:

Aw, this loses the symbol. Are you sure you want the output to be Currency
123 rather than usd 123? I mean this looks like a Currency is supposed to
be an equivalence class of sums of money in different currencies that are
worth the same - so then read . show should land you in the same equivalent
class regardless of which read and show are used, right?


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#1 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEJQrj731SBf2m7Ew6UiCDF_Hrxi1x_6ks5qgQs4gaJpZM4Jke8Q
.

from currency-convert.

Gurkenglas avatar Gurkenglas commented on August 15, 2024

You can if you add the symbol into the String as you already do in pprint - show (usd 100) = "usd 100", read "usd 100" = usd 100.

from currency-convert.

tuomas56 avatar tuomas56 commented on August 15, 2024

The whole idea (I probably haven't made this very clear in the docs) is that since the Currency type is exported from the module, you can define your own currencies for what you can support E.g:

type NEW = Currency "new"
new :: Fractional a => a -> NEW 
new = unsafeConvertCurrency . fromRational . toRational

The predefined ones are just for convenience. So defining Read in this way breaks this.

I am looking into SomeSymbol on GHC.TypeLits so I may be able to do this properly sometime in the future.

from currency-convert.

tuomas56 avatar tuomas56 commented on August 15, 2024

Fixed in latest commit.

from currency-convert.

Gurkenglas avatar Gurkenglas commented on August 15, 2024
C:\Users\Gurkenglas\Documents\GitHub\currency-convert>stack init --resolver=ghc-7.10.3 --force
Looking for .cabal or package.yaml files to use to init the project.
Using cabal packages:
- currency-convert.cabal

Selected resolver: ghc-7.10.3
*** Resolver ghc-7.10.3 will need external packages:

Using resolver: ghc-7.10.3
Using compiler: ghc-7.10.3
Asking cabal to calculate a build plan...
Successfully determined a build plan with 58 external dependencies.
Initialising configuration using resolver: ghc-7.10.3
Total number of user packages considered: 1
Warning! 58 external dependencies were added.
Overwriting existing configuration file: stack.yaml
All done.

C:\Users\Gurkenglas\Documents\GitHub\currency-convert>stack build
Warning (added by new or init): Specified resolver could not satisfy all dependencies. Some external packages have been added as dependencies.
You can suppress this message by removing it from stack.yaml

Warning (added by new or init): Specified resolver could not satisfy all dependencies. Some external packages have been added as dependencies.
You can suppress this message by removing it from stack.yaml


C:\Users\Gurkenglas\Documents\GitHub\currency-convert>stack ghci
Warning (added by new or init): Specified resolver could not satisfy all dependencies. Some external packages have been added as dependencies.
You can suppress this message by removing it from stack.yaml

Warning (added by new or init): Specified resolver could not satisfy all dependencies. Some external packages have been added as dependencies.
You can suppress this message by removing it from stack.yaml

Configuring GHCi with the following packages: currency-convert
GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Data.Currency.Convert ( C:\Users\Gurkenglas\Documents\GitHub\currency-convert\Data\Currency\Convert.hs, interpreted )
Ok, modules loaded: Data.Currency.Convert.
*Data.Currency.Convert Data.Currency.Convert> convert (usd 100) :: EUR

<interactive>:2:1:
    Non type-variable argument
      in the constraint: ?dict::[(String, Double)]
    (Use FlexibleContexts to permit this)
    When checking that `it' has the inferred type
      it :: (?dict::[(String, Double)], ?name::String) => EUR
*Data.Currency.Convert Data.Currency.Convert> show $ usd 100
"usd 100.0"
*Data.Currency.Convert Data.Currency.Convert> read $ "usd 100" :: USD
usd 100.0
*Data.Currency.Convert Data.Currency.Convert> read $ "usd 100" :: EUR
eur 100.0

convert should be equal to read . show, nevermind that convert didnt work on my system for some reason. Though on this one your mileage can vary - if different currencies in one file should not be read into one list of values of the same currency, you can ignore and close this.

Edit: I now see that there is no global converter and there is no pure way to convert between currencies. Should read fail on wrong currencies? Should there be a function that takes a converter and turns a String into any requested currency?

from currency-convert.

tuomas56 avatar tuomas56 commented on August 15, 2024

This is not the correct usage of convert. Read the README. Use it something like this:

>>> Converter convert <- getDefaultConverter
>>> convert (usd 100) :: EUR
eur 88.537

You don't use the convert function directly (that is why it is not exported from the module - the only reason you could access it is because you loaded the package source), but through the getConverter functions which run in the IO monad, allowing rate providers to use the IO monad to access conversion rates (e.g internet, files etc.)

The error you got means that no conversion rates were provided to convert as you did not get it through the getConverter function.

from currency-convert.

tuomas56 avatar tuomas56 commented on August 15, 2024

Also, reports like these should be in their own Github issue, please.

from currency-convert.

Related Issues (1)

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.