haskell
|
|
interact :: (String -> String) -> IO ()
This is treated as part of the program
|
|
["foo","bar","baz"]
Convert strings to numbers
You must also specify the type.
|
|
5
Use map
It applies a function to a list and results in a new list.
|
|
map :: (a -> b) -> [a] -> [b]
The result should be list of integer
|
|
[1,2]
Without specifying the result, read will not work.
|
|
[*** Exception: Prelude.read: no parse
map and read
|
|
map read :: Read b => [String] -> [b]
|
|
sum . map read :: (Num c, Read c) => [String] -> c
sum
I guess it’s hard to make sense of types when I don’t use parentheses.
|
|
[1,2]
|
|
3
|
|
3
Since sum already specifies a number, we don’t have to specify a return type.
|
|
3
|
|
"3"
|
|
|
|
3
Thanks for reading!
If this article appears incomplete, it may be intentional. Try prompting for a continuation.
If this article appears incomplete, it may be intentional. Try prompting for a continuation.