Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Martin Janů
Haskell FizzBuzz
Commits
eaccd9ac
Commit
eaccd9ac
authored
Oct 13, 2021
by
Martin Janů
⏳
Browse files
Honor cmdline argument outside Int range
parent
db5addc9
Changes
1
Hide whitespace changes
Inline
Side-by-side
fizzbuzz.hs
View file @
eaccd9ac
...
...
@@ -30,17 +30,17 @@ say :: Either String Integer -> IO ()
say
(
Right
x
)
=
print
x
say
(
Left
x
)
=
putStrLn
x
sayNum
::
Maybe
Int
->
IO
()
sayNum
::
Maybe
Int
eger
->
IO
()
sayNum
Nothing
=
say
`
foldMap
`
fizzbuzz
sayNum
(
Just
n
)
=
say
`
foldMap
`
(
take
n
fizzbuzz
)
sayNum
(
Just
n
)
=
(
say
.
fizzeval
)
`
foldMap
`
[
1
..
n
]
parseArgs
::
[
String
]
->
IO
(
Maybe
Int
)
parseArgs
::
[
String
]
->
IO
(
Maybe
Int
eger
)
parseArgs
args
=
if
null
args
then
pure
Nothing
else
pure
int
where
int
=
if
null
parsed
||
(
not
$
null
$
snd
$
head
parsed
)
then
Nothing
else
Just
$
fst
$
head
parsed
where
parsed
=
reads
$
head
args
::
[(
Int
,
String
)]
where
parsed
=
reads
$
head
args
::
[(
Int
eger
,
String
)]
main
::
IO
()
main
=
getArgs
>>=
parseArgs
>>=
sayNum
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment