File tree Expand file tree Collapse file tree 4 files changed +16
-8
lines changed Expand file tree Collapse file tree 4 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 1
- module WordNumber where
1
+ module WordNumber
2
+ ( digitToWord
3
+ , digits
4
+ , wordNumber
5
+ ) where
2
6
3
7
import Data.List (intersperse )
4
8
import Data.Maybe (fromJust )
5
9
10
+
6
11
digitToWord :: Int -> Maybe String
7
12
digitToWord 0 = Just " zero"
8
13
digitToWord 1 = Just " one"
@@ -16,10 +21,12 @@ digitToWord 8 = Just "eight"
16
21
digitToWord 9 = Just " nine"
17
22
digitToWord _ = Nothing
18
23
24
+
19
25
digits :: Int -> [Int ]
20
26
digits n
21
27
| n == 0 = []
22
28
| otherwise = digits (div n 10 ) ++ [mod n 10 ]
23
29
30
+
24
31
wordNumber :: Int -> String
25
32
wordNumber = concat . intersperse " -" . map (fromJust . digitToWord) . digits
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ module WordNumberTest where
3
3
import Test.Hspec
4
4
import WordNumber (digitToWord , digits , wordNumber )
5
5
6
+
6
7
main :: IO ()
7
8
main = hspec $ do
8
9
describe " digitToWord" $ do
Original file line number Diff line number Diff line change 1
1
name : chex
2
2
version : 0.1.0.0
3
- synopsis : Initial project template from stack
4
- description : Please see README.md
3
+ description : Chapter Exercises
5
4
homepage : https://github.com/dwayne/chex#readme
6
5
license : BSD3
7
6
license-file : LICENSE
8
7
author : Dwayne Crooks
9
8
maintainer : me@dwaynecrooks.com
10
- copyright : 2016 Dwayne Crooks
9
+ copyright : 2017 Dwayne Crooks
11
10
category : Text
12
11
build-type : Simple
13
12
cabal-version : >= 1.10
@@ -16,6 +15,7 @@ library
16
15
hs-source-dirs : .
17
16
default-language : Haskell2010
18
17
ghc-options : -Wall -fwarn-tabs
19
- exposed-modules : WordNumberTest
18
+ exposed-modules : WordNumber
19
+ , WordNumberTest
20
20
build-depends : base >= 4.7 && < 5
21
21
, hspec
Original file line number Diff line number Diff line change 15
15
# resolver:
16
16
# name: custom-snapshot
17
17
# location: "./custom-snapshot.yaml"
18
- resolver : lts-5.17
18
+ resolver : lts-8.2
19
19
20
20
# User packages to be built.
21
21
# Various formats can be used as shown in the example below.
@@ -52,7 +52,7 @@ extra-package-dbs: []
52
52
#
53
53
# Require a specific version of stack, using version ranges
54
54
# require-stack-version: -any # Default
55
- # require-stack-version: ">=1.1 "
55
+ # require-stack-version: ">=1.3 "
56
56
#
57
57
# Override the architecture used by stack, especially useful on Windows
58
58
# arch: i386
@@ -63,4 +63,4 @@ extra-package-dbs: []
63
63
# extra-lib-dirs: [/path/to/dir]
64
64
#
65
65
# Allow a newer minor version of GHC than the snapshot specifies
66
- # compiler-check: newer-minor
66
+ # compiler-check: newer-minor
You can’t perform that action at this time.
0 commit comments