Skip to content

Commit c26f037

Browse files
committed
Update my "Validating numbers into words" solution from ch14
1 parent a9cbeed commit c26f037

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

ch14/chex/WordNumber.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
module WordNumber where
1+
module WordNumber
2+
( digitToWord
3+
, digits
4+
, wordNumber
5+
) where
26

37
import Data.List (intersperse)
48
import Data.Maybe (fromJust)
59

10+
611
digitToWord :: Int -> Maybe String
712
digitToWord 0 = Just "zero"
813
digitToWord 1 = Just "one"
@@ -16,10 +21,12 @@ digitToWord 8 = Just "eight"
1621
digitToWord 9 = Just "nine"
1722
digitToWord _ = Nothing
1823

24+
1925
digits :: Int -> [Int]
2026
digits n
2127
| n == 0 = []
2228
| otherwise = digits (div n 10) ++ [mod n 10]
2329

30+
2431
wordNumber :: Int -> String
2532
wordNumber = concat . intersperse "-" . map (fromJust . digitToWord) . digits

ch14/chex/WordNumberTest.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module WordNumberTest where
33
import Test.Hspec
44
import WordNumber (digitToWord, digits, wordNumber)
55

6+
67
main :: IO ()
78
main = hspec $ do
89
describe "digitToWord" $ do

ch14/chex/chex.cabal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
name: chex
22
version: 0.1.0.0
3-
synopsis: Initial project template from stack
4-
description: Please see README.md
3+
description: Chapter Exercises
54
homepage: https://github.com/dwayne/chex#readme
65
license: BSD3
76
license-file: LICENSE
87
author: Dwayne Crooks
98
maintainer: me@dwaynecrooks.com
10-
copyright: 2016 Dwayne Crooks
9+
copyright: 2017 Dwayne Crooks
1110
category: Text
1211
build-type: Simple
1312
cabal-version: >=1.10
@@ -16,6 +15,7 @@ library
1615
hs-source-dirs: .
1716
default-language: Haskell2010
1817
ghc-options: -Wall -fwarn-tabs
19-
exposed-modules: WordNumberTest
18+
exposed-modules: WordNumber
19+
, WordNumberTest
2020
build-depends: base >= 4.7 && < 5
2121
, hspec

ch14/chex/stack.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# resolver:
1616
# name: custom-snapshot
1717
# location: "./custom-snapshot.yaml"
18-
resolver: lts-5.17
18+
resolver: lts-8.2
1919

2020
# User packages to be built.
2121
# Various formats can be used as shown in the example below.
@@ -52,7 +52,7 @@ extra-package-dbs: []
5252
#
5353
# Require a specific version of stack, using version ranges
5454
# require-stack-version: -any # Default
55-
# require-stack-version: ">=1.1"
55+
# require-stack-version: ">=1.3"
5656
#
5757
# Override the architecture used by stack, especially useful on Windows
5858
# arch: i386
@@ -63,4 +63,4 @@ extra-package-dbs: []
6363
# extra-lib-dirs: [/path/to/dir]
6464
#
6565
# Allow a newer minor version of GHC than the snapshot specifies
66-
# compiler-check: newer-minor
66+
# compiler-check: newer-minor

0 commit comments

Comments
 (0)