Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Support for Rational configuration values #3

basvandijk opened this Issue · 2 comments

2 participants


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:

  • Change the Number constructor from: Number Integer to: Number Number where the Number type will be defined in attoparsec-text (or just in configurator) and will be similar to the Number type from attoparsec but uses a Rational instead of a Double. See the following for an implementation. The following number parser should also be defined:
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
  • Change the Number constructor from: Number Integer to: Number Rational. In the previous solution, if a user wants to check if a number is an integer or a rational she can write a pattern match. In this solution this is still also possible by checking if the denominator is 1.

What do you think?

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

@basvandijk basvandijk referenced this issue from a commit in basvandijk/configurator
@basvandijk basvandijk Changed Number constructor from Integer to Rational
Fixes issue #3

Your changes don't compile:

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), ....]'

Thanks for merging this Bryan!

@basvandijk basvandijk closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.