@@ -1,4 +1,4 @@
1−{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}
1+{-# LANGUAGE RankNTypes, ScopedTypeVariables, PatternGuards #-}
22
33module Idris.Primitives(elabPrims) where
44
@@ -34,39 +34,7 @@ partial = Partial NotCovering
3434
3535primitives =
3636 -- operators
37− [Prim (UN "prim__addInt") (ty [IType, IType] IType) 2 (iBin (+))
38− (2, LPlus ITNative) total,
39− Prim (UN "prim__subInt") (ty [IType, IType] IType) 2 (iBin (-))
40− (2, LMinus ITNative) total,
41− Prim (UN "prim__mulInt") (ty [IType, IType] IType) 2 (iBin (*))
42− (2, LTimes ITNative) total,
43− Prim (UN "prim__divInt") (ty [IType, IType] IType) 2 (iBin div)
44− (2, LSDiv ITNative) partial,
45− Prim (UN "prim__modInt") (ty [IType, IType] IType) 2 (iBin mod)
46− (2, LSRem ITNative) partial,
47− Prim (UN "prim__andInt") (ty [IType, IType] IType) 2 (iBin (.&.))
48− (2, LAnd ITNative) partial,
49− Prim (UN "prim__orInt") (ty [IType, IType] IType) 2 (iBin (.|.))
50− (2, LOr ITNative) partial,
51− Prim (UN "prim__xorInt") (ty [IType, IType] IType) 2 (iBin xor)
52− (2, LXOr ITNative) partial,
53− Prim (UN "prim__shLInt") (ty [IType, IType] IType) 2 (iBin shiftL)
54− (2, LSHL ITNative) partial,
55− Prim (UN "prim__shRInt") (ty [IType, IType] IType) 2 (iBin shiftR)
56− (2, LASHR ITNative) partial,
57− Prim (UN "prim__complInt") (ty [IType] IType) 1 (iUn complement)
58− (1, LCompl ITNative) partial,
59− Prim (UN "prim__eqInt") (ty [IType, IType] IType) 2 (biBin (==))
60− (2, LEq ITNative) total,
61− Prim (UN "prim__ltInt") (ty [IType, IType] IType) 2 (biBin (<))
62− (2, LLt ITNative) total,
63− Prim (UN "prim__lteInt") (ty [IType, IType] IType) 2 (biBin (<=))
64− (2, LLe ITNative) total,
65− Prim (UN "prim__gtInt") (ty [IType, IType] IType) 2 (biBin (>))
66− (2, LGt ITNative) total,
67− Prim (UN "prim__gteInt") (ty [IType, IType] IType) 2 (biBin (>=))
68− (2, LGe ITNative) total,
69− Prim (UN "prim__eqChar") (ty [ChType, ChType] IType) 2 (bcBin (==))
37+ [Prim (UN "prim__eqChar") (ty [ChType, ChType] IType) 2 (bcBin (==))
7038 (2, LEq ITNative) total,
7139 Prim (UN "prim__ltChar") (ty [ChType, ChType] IType) 2 (bcBin (<))
7240 (2, LLt ITNative) total,
@@ -80,55 +48,59 @@ primitives =
8048 iCoerce IT8 IT16 "zext" zext LZExt,
8149 iCoerce IT8 IT32 "zext" zext LZExt,
8250 iCoerce IT8 IT64 "zext" zext LZExt,
51+ iCoerce IT8 ITBig "zext" zext LZExt,
52+ iCoerce IT8 ITNative "zext" zext LZExt,
8353 iCoerce IT16 IT32 "zext" zext LZExt,
8454 iCoerce IT16 IT64 "zext" zext LZExt,
55+ iCoerce IT16 ITBig "zext" zext LZExt,
56+ iCoerce IT16 ITNative "zext" zext LZExt,
8557 iCoerce IT32 IT64 "zext" zext LZExt,
58+ iCoerce IT32 ITBig "zext" zext LZExt,
59+ iCoerce IT32 ITNative "zext" zext LZExt,
60+ iCoerce IT64 ITBig "zext" zext LZExt,
61+ iCoerce ITNative ITBig "zext" zext LZExt,
62+ iCoerce ITNative IT64 "zext" zext LZExt,
63+ iCoerce ITNative IT32 "zext" zext LZExt,
64+ iCoerce ITNative IT16 "zext" zext LZExt,
8665
8766 iCoerce IT8 IT16 "sext" sext LSExt,
8867 iCoerce IT8 IT32 "sext" sext LSExt,
8968 iCoerce IT8 IT64 "sext" sext LSExt,
69+ iCoerce IT8 ITBig "sext" sext LSExt,
70+ iCoerce IT8 ITNative "sext" sext LSExt,
9071 iCoerce IT16 IT32 "sext" sext LSExt,
9172 iCoerce IT16 IT64 "sext" sext LSExt,
73+ iCoerce IT16 ITBig "sext" sext LSExt,
74+ iCoerce IT16 ITNative "sext" sext LSExt,
9275 iCoerce IT32 IT64 "sext" sext LSExt,
76+ iCoerce IT32 ITBig "sext" sext LSExt,
77+ iCoerce IT32 ITNative "sext" sext LSExt,
78+ iCoerce IT64 ITBig "sext" sext LSExt,
79+ iCoerce ITNative ITBig "sext" sext LSExt,
80+ iCoerce ITNative ITBig "sext" sext LSExt,
81+ iCoerce ITNative IT64 "sext" sext LSExt,
82+ iCoerce ITNative IT32 "sext" sext LSExt,
83+ iCoerce ITNative IT16 "sext" sext LSExt,
9384
9485 iCoerce IT16 IT8 "trunc" trunc LTrunc,
9586 iCoerce IT32 IT8 "trunc" trunc LTrunc,
9687 iCoerce IT64 IT8 "trunc" trunc LTrunc,
88+ iCoerce ITBig IT8 "trunc" trunc LTrunc,
89+ iCoerce ITNative IT8 "trunc" trunc LTrunc,
9790 iCoerce IT32 IT16 "trunc" trunc LTrunc,
9891 iCoerce IT64 IT16 "trunc" trunc LTrunc,
92+ iCoerce ITBig IT16 "trunc" trunc LTrunc,
93+ iCoerce ITNative IT16 "trunc" trunc LTrunc,
9994 iCoerce IT64 IT32 "trunc" trunc LTrunc,
95+ iCoerce ITBig IT32 "trunc" trunc LTrunc,
96+ iCoerce ITNative IT32 "trunc" trunc LTrunc,
97+ iCoerce ITBig IT64 "trunc" trunc LTrunc,
98+ iCoerce IT16 ITNative "trunc" trunc LTrunc,
99+ iCoerce IT32 ITNative "trunc" trunc LTrunc,
100+ iCoerce IT64 ITNative "trunc" trunc LTrunc,
101+ iCoerce ITBig ITNative "trunc" trunc LTrunc,
102+ iCoerce ITNative IT64 "trunc" trunc LTrunc,
100103
101− Prim (UN "prim__intToB8") (ty [IType] B8Type) 1 intToBits8
102− (1, LIntB8) total,
103− Prim (UN "prim__intToB16") (ty [IType] B16Type) 1 intToBits16
104− (1, LIntB16) total,
105− Prim (UN "prim__intToB32") (ty [IType] B32Type) 1 intToBits32
106− (1, LIntB32) total,
107− Prim (UN "prim__intToB64") (ty [IType] B64Type) 1 intToBits64
108− (1, LIntB64) total,
109− Prim (UN "prim__B32ToInt") (ty [B32Type] IType) 1 bits32ToInt
110− (1, LB32Int) total,
111−
112− Prim (UN "prim__addBigInt") (ty [BIType, BIType] BIType) 2 (bBin (+))
113− (2, LBPlus) total,
114− Prim (UN "prim__subBigInt") (ty [BIType, BIType] BIType) 2 (bBin (-))
115− (2, LBMinus) total,
116− Prim (UN "prim__mulBigInt") (ty [BIType, BIType] BIType) 2 (bBin (*))
117− (2, LBTimes) total,
118− Prim (UN "prim__divBigInt") (ty [BIType, BIType] BIType) 2 (bBin div)
119− (2, LBDiv) partial,
120− Prim (UN "prim__modBigInt") (ty [BIType, BIType] BIType) 2 (bBin mod)
121− (2, LBMod) partial,
122− Prim (UN "prim__eqBigInt") (ty [BIType, BIType] IType) 2 (bbBin (==))
123− (2, LBEq) total,
124− Prim (UN "prim__ltBigInt") (ty [BIType, BIType] IType) 2 (bbBin (<))
125− (2, LBLt) total,
126− Prim (UN "prim__lteBigInt") (ty [BIType, BIType] IType) 2 (bbBin (<=))
127− (2, LBLe) total,
128− Prim (UN "prim__gtBigInt") (ty [BIType, BIType] IType) 2 (bbBin (>))
129− (2, LBGt) total,
130− Prim (UN "prim__gtBigInt") (ty [BIType, BIType] IType) 2 (bbBin (>=))
131− (2, LBGe) total,
132104 Prim (UN "prim__addFloat") (ty [FlType, FlType] FlType) 2 (fBin (+))
133105 (2, LFPlus) total,
134106 Prim (UN "prim__subFloat") (ty [FlType, FlType] FlType) 2 (fBin (-))
@@ -156,30 +128,14 @@ primitives =
156128 Prim (UN "prim_lenString") (ty [StrType] IType) 1 (p_strLen)
157129 (1, LStrLen) total,
158130 -- Conversions
159− Prim (UN "prim__strToInt") (ty [StrType] IType) 1 (c_strToInt)
160− (1, LStrInt) total,
161− Prim (UN "prim__intToStr") (ty [IType] StrType) 1 (c_intToStr)
162− (1, LIntStr) total,
163131 Prim (UN "prim__charToInt") (ty [ChType] IType) 1 (c_charToInt)
164− (1, LChInt) total,
132+ (1, LChInt ITNative) total,
165133 Prim (UN "prim__intToChar") (ty [IType] ChType) 1 (c_intToChar)
166− (1, LIntCh) total,
167− Prim (UN "prim__intToBigInt") (ty [IType] BIType) 1 (c_intToBigInt)
168− (1, LIntBig) total,
169− Prim (UN "prim__bigIntToInt") (ty [BIType] IType) 1 (c_bigIntToInt)
170− (1, LBigInt) total,
171− Prim (UN "prim__strToBigInt") (ty [StrType] BIType) 1 (c_strToBigInt)
172− (1, LStrBig) total,
173− Prim (UN "prim__bigIntToStr") (ty [BIType] StrType) 1 (c_bigIntToStr)
174− (1, LBigStr) total,
134+ (1, LIntCh ITNative) total,
175135 Prim (UN "prim__strToFloat") (ty [StrType] FlType) 1 (c_strToFloat)
176136 (1, LStrFloat) total,
177137 Prim (UN "prim__floatToStr") (ty [FlType] StrType) 1 (c_floatToStr)
178138 (1, LFloatStr) total,
179− Prim (UN "prim__intToFloat") (ty [IType] FlType) 1 (c_intToFloat)
180− (1, LIntFloat) total,
181− Prim (UN "prim__floatToInt") (ty [FlType] IType) 1 (c_floatToInt)
182− (1, LFloatInt) total,
183139
184140 Prim (UN "prim__floatExp") (ty [FlType] FlType) 1 (p_floatExp)
185141 (1, LFExp) total,
@@ -223,7 +179,7 @@ primitives =
223179 (0, LStdIn) partial,
224180 Prim (UN "prim__believe_me") believeTy 3 (p_believeMe)
225181 (3, LNoOp) partial -- ahem
226− ] ++ concatMap intOps [IT8, IT16, IT32, IT64]
182+ ] ++ concatMap intOps [IT8, IT16, IT32, IT64, ITBig, ITNative]
227183
228184intOps ity =
229185 [ iCmp ity "lt" (bCmp ity (<)) LLt total
@@ -245,13 +201,26 @@ intOps ity =
245201 , iBinOp ity "or" (bitBin ity (.|.)) LOr total
246202 , iBinOp ity "xor" (bitBin ity (xor)) LXOr total
247203 , iUnOp ity "compl" (bUn ity complement) LCompl total
204+ , Prim (UN $ "prim__toStr" ++ intTyName ity) (ty [intTyToConst ity] StrType) 1 intToStr
205+ (1, LIntStr ity) total
206+ , Prim (UN $ "prim__fromStr" ++ intTyName ity) (ty [StrType] (intTyToConst ity)) 1 (strToInt ity)
207+ (1, LStrInt ity) total
208+ , Prim (UN $ "prim__toFloat" ++ intTyName ity) (ty [intTyToConst ity] FlType) 1 intToFloat
209+ (1, LIntFloat ity) total
210+ , Prim (UN $ "prim__fromFloat" ++ intTyName ity) (ty [FlType] (intTyToConst ity)) 1 (floatToInt ity)
211+ (1, LFloatInt ity) total
248212 ]
249213
250−iCmp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ "B" ++ show (intTyWidth ity)) (ty (replicate 2 $ intTyToConst ity) IType) 2 impl (2, irop ity) totality
251−iBinOp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ "B" ++ show (intTyWidth ity)) (ty (replicate 2 $ intTyToConst ity) (intTyToConst ity)) 2 impl (2, irop ity) totality
252−iUnOp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ "B" ++ show (intTyWidth ity)) (ty [intTyToConst ity] (intTyToConst ity)) 1 impl (1, irop ity) totality
214+intTyName :: IntTy -> String
215+intTyName ITNative = "Int"
216+intTyName ITBig = "BigInt"
217+intTyName sized = "B" ++ show (intTyWidth sized)
218+
219+iCmp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ intTyName ity) (ty (replicate 2 $ intTyToConst ity) IType) 2 impl (2, irop ity) totality
220+iBinOp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ intTyName ity) (ty (replicate 2 $ intTyToConst ity) (intTyToConst ity)) 2 impl (2, irop ity) totality
221+iUnOp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ intTyName ity) (ty [intTyToConst ity] (intTyToConst ity)) 1 impl (1, irop ity) totality
253222iCoerce from to op impl irop =
254− Prim (UN $ "prim__" ++ op ++ "B" ++ show (intTyWidth from) ++ "_" ++ show (intTyWidth to))
223+ Prim (UN $ "prim__" ++ op ++ intTyName from ++ "_" ++ intTyName to)
255224 (ty [intTyToConst from] (intTyToConst to)) 1 (impl from to) (1, irop from to) total
256225
257226p_believeMe [_,_,x] = Just x
@@ -329,6 +298,8 @@ bUn IT8 op [VConstant (B8 x)] = Just $ VConstant (B8 (op x))
329298bUn IT16 op [VConstant (B16 x)] = Just $ VConstant (B16 (op x))
330299bUn IT32 op [VConstant (B32 x)] = Just $ VConstant (B32 (op x))
331300bUn IT64 op [VConstant (B64 x)] = Just $ VConstant (B64 (op x))
301+bUn ITBig op [VConstant (BI x)] = Just $ VConstant (BI (op x))
302+bUn ITNative op [VConstant (I x)] = Just $ VConstant (I (op x))
332303bUn _ _ _ = Nothing
333304
334305bitBin :: IntTy -> (forall a. (Bits a, Integral a) => a -> a -> a) -> [Value] -> Maybe Value
@@ -336,6 +307,8 @@ bitBin IT8 op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (B8 (o
336307bitBin IT16 op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (B16 (op x y))
337308bitBin IT32 op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (B32 (op x y))
338309bitBin IT64 op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (B64 (op x y))
310+bitBin ITBig op [VConstant (BI x), VConstant (BI y)] = Just $ VConstant (BI (op x y))
311+bitBin ITNative op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
339312bitBin _ _ _ = Nothing
340313
341314bCmp :: IntTy -> (forall a. Ord a => a -> a -> Bool) -> [Value] -> Maybe Value
@@ -343,73 +316,71 @@ bCmp IT8 op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (I (if (o
343316bCmp IT16 op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
344317bCmp IT32 op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
345318bCmp IT64 op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
319+bCmp ITBig op [VConstant (BI x), VConstant (BI y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
320+bCmp ITNative op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
346321bCmp _ _ _ = Nothing
347322
348−toB IT8 x = VConstant (B8 (fromIntegral x))
349−toB IT16 x = VConstant (B16 (fromIntegral x))
350−toB IT32 x = VConstant (B32 (fromIntegral x))
351−toB IT64 x = VConstant (B64 (fromIntegral x))
352−
353−zext IT8 IT16 [VConstant (B8 x)] = Just $ VConstant (B16 (fromIntegral x))
354−zext IT8 IT32 [VConstant (B8 x)] = Just $ VConstant (B32 (fromIntegral x))
355−zext IT8 IT64 [VConstant (B8 x)] = Just $ VConstant (B64 (fromIntegral x))
356−zext IT16 IT32 [VConstant (B16 x)] = Just $ VConstant (B32 (fromIntegral x))
357−zext IT16 IT64 [VConstant (B16 x)] = Just $ VConstant (B64 (fromIntegral x))
358−zext IT32 IT64 [VConstant (B32 x)] = Just $ VConstant (B64 (fromIntegral x))
323+toInt IT8 x = VConstant (B8 (fromIntegral x))
324+toInt IT16 x = VConstant (B16 (fromIntegral x))
325+toInt IT32 x = VConstant (B32 (fromIntegral x))
326+toInt IT64 x = VConstant (B64 (fromIntegral x))
327+toInt ITBig x = VConstant (BI (fromIntegral x))
328+toInt ITNative x = VConstant (I (fromIntegral x))
329+
330+intToInt IT8 out [VConstant (B8 x)] = Just $ toInt out x
331+intToInt IT16 out [VConstant (B16 x)] = Just $ toInt out x
332+intToInt IT32 out [VConstant (B32 x)] = Just $ toInt out x
333+intToInt IT64 out [VConstant (B64 x)] = Just $ toInt out x
334+intToInt ITBig out [VConstant (BI x)] = Just $ toInt out x
335+intToInt ITNative out [VConstant (I x)] = Just $ toInt out x
336+intToInt _ _ _ = Nothing
337+
338+zext from ITBig val = intToInt from ITBig val
339+zext ITBig _ _ = Nothing
340+zext from to val
341+ | intTyWidth from < intTyWidth to = intToInt from to val
359342zext _ _ _ = Nothing
360343
361−sext IT8 IT16 [VConstant (B8 x)] = Just $ VConstant (B16 (fromIntegral (fromIntegral x :: Int8)))
362−sext IT8 IT32 [VConstant (B8 x)] = Just $ VConstant (B32 (fromIntegral (fromIntegral x :: Int8)))
363−sext IT8 IT64 [VConstant (B8 x)] = Just $ VConstant (B64 (fromIntegral (fromIntegral x :: Int8)))
364−sext IT16 IT32 [VConstant (B16 x)] = Just $ VConstant (B32 (fromIntegral (fromIntegral x :: Int16)))
365−sext IT16 IT64 [VConstant (B16 x)] = Just $ VConstant (B64 (fromIntegral (fromIntegral x :: Int16)))
366−sext IT32 IT64 [VConstant (B32 x)] = Just $ VConstant (B64 (fromIntegral (fromIntegral x :: Int32)))
367−sext _ _ _ = Nothing
368−
369−trunc IT16 IT8 [VConstant (B16 x)] = Just $ VConstant (B8 (fromIntegral x))
370−trunc IT32 IT8 [VConstant (B32 x)] = Just $ VConstant (B8 (fromIntegral x))
371−trunc IT64 IT8 [VConstant (B64 x)] = Just $ VConstant (B8 (fromIntegral x))
372−trunc IT32 IT16 [VConstant (B32 x)] = Just $ VConstant (B16 (fromIntegral x))
373−trunc IT64 IT16 [VConstant (B64 x)] = Just $ VConstant (B16 (fromIntegral x))
374−trunc IT64 IT32 [VConstant (B64 x)] = Just $ VConstant (B32 (fromIntegral x))
344+sext IT8 out [VConstant (B8 x)] = Just $ toInt out (fromIntegral x :: Int8)
345+sext IT16 out [VConstant (B16 x)] = Just $ toInt out (fromIntegral x :: Int16)
346+sext IT32 out [VConstant (B32 x)] = Just $ toInt out (fromIntegral x :: Int32)
347+sext IT64 out [VConstant (B64 x)] = Just $ toInt out (fromIntegral x :: Int64)
348+sext ITBig _ _ = Nothing
349+sext from to val = intToInt from to val
350+
351+trunc ITBig to val = intToInt ITBig to val
352+trunc _ ITBig _ = Nothing
353+trunc from to val | intTyWidth from > intTyWidth to = intToInt from to val
375354trunc _ _ _ = Nothing
376355
377−intToBits8 [VConstant (I x)] = Just $ toB IT8 x
378−intToBits8 _ = Nothing
379−intToBits16 [VConstant (I x)] = Just $ toB IT16 x
380−intToBits16 _ = Nothing
381−intToBits32 [VConstant (I x)] = Just $ toB IT32 x
382−intToBits32 _ = Nothing
383−intToBits64 [VConstant (I x)] = Just $ toB IT64 x
384−intToBits64 _ = Nothing
385−
386−bits32ToInt [VConstant (B32 x)] = Just $ VConstant (I (fromIntegral x))
387−bits32ToInt _ = Nothing
388−
389−c_intToStr [VConstant (I x)] = Just $ VConstant (Str (show x))
390−c_intToStr _ = Nothing
391−c_strToInt [VConstant (Str x)] = case reads x of
392− [(n,"")] -> Just $ VConstant (I n)
393− _ -> Just $ VConstant (I 0)
394−c_strToInt _ = Nothing
356+getInt :: [Value] -> Maybe Integer
357+getInt [VConstant (B8 x)] = Just . toInteger $ x
358+getInt [VConstant (B16 x)] = Just . toInteger $ x
359+getInt [VConstant (B32 x)] = Just . toInteger $ x
360+getInt [VConstant (B64 x)] = Just . toInteger $ x
361+getInt [VConstant (I x)] = Just . toInteger $ x
362+getInt [VConstant (BI x)] = Just x
363+getInt _ = Nothing
364+
365+intToStr val | Just i <- getInt val = Just $ VConstant (Str (show i))
366+intToStr _ = Nothing
367+
368+strToInt ity [VConstant (Str x)] = case reads x of
369+ [(n,"")] -> Just $ toInt ity (n :: Integer)
370+ _ -> Just $ VConstant (I 0)
371+strToInt _ _ = Nothing
372+
373+intToFloat val | Just i <- getInt val = Just $ VConstant (Fl (fromIntegral i))
374+intToFloat _ = Nothing
375+
376+floatToInt ity [VConstant (Fl x)] = Just $ toInt ity (truncate x :: Integer)
377+floatToInt _ _ = Nothing
395378
396379c_intToChar [VConstant (I x)] = Just $ VConstant (Ch (toEnum x))
397380c_intToChar _ = Nothing
398381c_charToInt [VConstant (Ch x)] = Just $ VConstant (I (fromEnum x))
399382c_charToInt _ = Nothing
400383
401−c_intToBigInt [VConstant (I x)] = Just $ VConstant (BI (fromIntegral x))
402−c_intToBigInt _ = Nothing
403−c_bigIntToInt [VConstant (BI x)] = Just $ VConstant (I (fromInteger x))
404−c_bigIntToInt _ = Nothing
405−
406−c_bigIntToStr [VConstant (BI x)] = Just $ VConstant (Str (show x))
407−c_bigIntToStr _ = Nothing
408−c_strToBigInt [VConstant (Str x)] = case reads x of
409− [(n,"")] -> Just $ VConstant (BI n)
410− _ -> Just $ VConstant (BI 0)
411−c_strToBigInt _ = Nothing
412−
413384c_floatToStr [VConstant (Fl x)] = Just $ VConstant (Str (show x))
414385c_floatToStr _ = Nothing
415386c_strToFloat [VConstant (Str x)] = case reads x of
@@ -417,12 +388,6 @@ c_strToFloat [VConstant (Str x)] = case reads x of
417388 _ -> Just $ VConstant (Fl 0)
418389c_strToFloat _ = Nothing
419390
420−c_floatToInt [VConstant (Fl x)] = Just $ VConstant (I (truncate x))
421−c_floatToInt _ = Nothing
422−
423−c_intToFloat [VConstant (I x)] = Just $ VConstant (Fl (fromIntegral x))
424−c_intToFloat _ = Nothing
425−
426391p_fPrim f [VConstant (Fl x)] = Just $ VConstant (Fl (f x))
427392p_fPrim f _ = Nothing
428393