Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit d4bef3a

Browse files
committed
Change internal DoubleLiteral type to Scientific
To avoid the Double -> Scientific conversions
1 parent 702b550 commit d4bef3a

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/Expr.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
module Expr where
44

55
import Data.Maybe (fromMaybe)
6+
import Data.Scientific (Scientific)
67
import Data.String (IsString (..))
78
import Data.Text (Text)
89
import qualified Data.Text as T
9-
import Text.Parsec (many, many1, optionMaybe, parse,
10-
sepBy, (<|>))
11-
import Text.Parsec.Char (char, digit, letter, spaces, noneOf)
10+
import Text.Parsec (many, many1, optionMaybe, parse, sepBy,
11+
(<|>))
12+
import Text.Parsec.Char (char, digit, letter, noneOf, spaces)
1213
import Text.Parsec.Error (ParseError)
1314
import Text.Parsec.Text (Parser)
1415

1516
-- $setup
1617
-- >>> :set -XOverloadedStrings
1718

1819
data Expr = IntLiteral Integer
19-
| DoubleLiteral Double
20+
| DoubleLiteral Scientific
2021
| StringLiteral Text
2122
| FunctionCall { fcName :: Text, fcArgs :: [Expr] }
2223
deriving (Show, Eq)
@@ -46,7 +47,6 @@ number = do
4647
(Just _) -> do
4748
fractional <- many digit
4849
let
49-
value :: Double
5050
value = read $ integer <> "." <> fractional
5151
pure $ DoubleLiteral value
5252

src/Fake.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fromFile fileName = do
162162
eval :: Expr -> State Value
163163
eval (IntLiteral x) = pure $ Number $ fromInteger x
164164
eval (StringLiteral x) = pure $ String x
165-
eval (DoubleLiteral x) = pure $ Number $ S.fromFloatDigits x
165+
eval (DoubleLiteral x) = pure $ Number x
166166
eval (FunctionCall "uuid4" []) = String . UUID.toText <$> withStdGen random
167167
eval (FunctionCall "uuid1" []) = String . UUID.toText <$> uuid1
168168
eval (FunctionCall "randomInt" [lower, upper]) = randomInt lower upper

0 commit comments

Comments
 (0)