Skip to content

Commit 00b71ea

Browse files
committed
Merge pull request #1 from haskellcamargo/master
Implemented type conversion from string to int and float
2 parents 218f568 + bee2ff9 commit 00b71ea

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Conversion.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ isTruthy = getBool . castToBool
2424
where getBool (PHPBool b) = b
2525

2626
castToInt :: PHPValue -> PHPValue
27-
castToInt (PHPString _) = error "string to int behavior is not implemented"
27+
castToInt (PHPString a) = PHPInt $ read a :: PHPValue
2828
castToInt a@(PHPInt _) = a
2929
castToInt (PHPFloat a) = PHPInt $ floor a
3030
castToInt (PHPBool a) | a == True = PHPInt 1
3131
| a == False = PHPInt 0
3232
castToInt PHPNull = PHPInt 0
3333

3434
castToFloat :: PHPValue -> PHPValue
35-
castToFloat (PHPString _) = error "undefined behavior for string to float"
35+
castToFloat (PHPString a) = PHPFloat $ read a :: PHPValue
3636
castToFloat (PHPInt a) = PHPFloat $ fromInteger a
3737
castToFloat a@(PHPFloat _) = a
3838
castToFloat PHPNull = PHPFloat 0

0 commit comments

Comments
 (0)