bos / configurator

A Haskell library supporting flexible, dynamic file-based configuration.
Other
128 stars 27 forks source link

Support for Rational configuration values #3

Closed basvandijk closed 12 years ago

basvandijk commented 12 years ago

Hi Bryan,

I would like to use configurator but I need to be a able to specify Rational configuration values.

I see two ways of adding these:

number :: Parser Number
number = floaty $ \real frac fracDenom ->
         if frac == 0 && fracDenom == 0
         then I real
         else R $! asRational real frac fracDenom

asRational :: Integer -> Integer -> Integer -> Rational
asRational real frac fracDenom = real % 1 + frac % fracDenom

What do you think?

(In my own private code I will go for the latter solution as that is much simpler than the former.)

bos commented 12 years ago

Your changes don't compile:

Data/Configurator/Parser.hs:87:22:
No instance for (RealFloat Rational)
  arising from a use of `rational'
Possible fix: add an instance declaration for (RealFloat Rational)
In the second argument of `(<$>)', namely `rational'
In the expression: Number <$> rational
In the first argument of `mconcat', namely
  `[string "on" *> pure (Bool True),
    string "off" *> pure (Bool False),
    string "true" *> pure (Bool True),
    string "false" *> pure (Bool False), ....]'
basvandijk commented 12 years ago

Thanks for merging this Bryan!