blob: f00d2df6d6f355bd628105e8cb1ee65fc3a1694b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
module Grasp.Types.Instruction (
Instruction,
mk,
toString,
toFloat,
toInt
) where
import Text.Read( readMaybe )
newtype Instruction = Instruction String
deriving (Show, Eq)
mk :: String -> Instruction
mk = Instruction
toString :: Instruction -> String
toString (Instruction i) = i
toFloat :: Instruction -> Maybe Float
toFloat (Instruction i) = readMaybe i
toInt :: Instruction -> Maybe Int
toInt (Instruction i) = do
f <- (readMaybe :: String -> Maybe Float) i
let g = round f
h = fromIntegral g
r <- if (f == h) then Just g else Nothing
return r
|