Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: kerryb/seven-languages-in-seven-weeks
base: 87b13433e3
...
head fork: kerryb/seven-languages-in-seven-weeks
compare: 37d28af6f7
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 22 additions and 0 deletions.
  1. +22 −0 haskell/day2/StringToNumber.hs
22 haskell/day2/StringToNumber.hs
View
@@ -0,0 +1,22 @@
+module StringToNumber where
+ import Test.QuickCheck
+
+ to_number s = foldl (\a b -> 10 * a + (to_digit b)) 0 digits where
+ digits = (filter (\x -> elem x ['0'..'9']) s)
+ to_digit c = case c of
+ '1' -> 1
+ '2' -> 2
+ '3' -> 3
+ '4' -> 4
+ '5' -> 5
+ '6' -> 6
+ '7' -> 7
+ '8' -> 8
+ '9' -> 9
+ otherwise -> 0
+
+ {-tests-}
+
+ prop_empty_is_zero = to_number "" == 0
+ prop_simple_integer = to_number "123" == 123
+ prop_ignore_punctuation = to_number "$123,456" == 123456

No commit comments for this range

Something went wrong with that request. Please try again.