有时当我想使用 时wget
,我最终会用 Python 打印一堆行,如下所示:
>>> for i in range(25):
... print "http://www.theoi.com/Text/HomerOdyssey", i, ".html"
...
http://www.theoi.com/Text/HomerOdyssey 0 .html
http://www.theoi.com/Text/HomerOdyssey 1 .html
http://www.theoi.com/Text/HomerOdyssey 2 .html
http://www.theoi.com/Text/HomerOdyssey 3 .html
http://www.theoi.com/Text/HomerOdyssey 4 .html
http://www.theoi.com/Text/HomerOdyssey 5 .html
http://www.theoi.com/Text/HomerOdyssey 6 .html
http://www.theoi.com/Text/HomerOdyssey 7 .html
http://www.theoi.com/Text/HomerOdyssey 8 .html
http://www.theoi.com/Text/HomerOdyssey 9 .html
http://www.theoi.com/Text/HomerOdyssey 10 .html
http://www.theoi.com/Text/HomerOdyssey 11 .html
http://www.theoi.com/Text/HomerOdyssey 12 .html
http://www.theoi.com/Text/HomerOdyssey 13 .html
http://www.theoi.com/Text/HomerOdyssey 14 .html
http://www.theoi.com/Text/HomerOdyssey 15 .html
http://www.theoi.com/Text/HomerOdyssey 16 .html
http://www.theoi.com/Text/HomerOdyssey 17 .html
http://www.theoi.com/Text/HomerOdyssey 18 .html
http://www.theoi.com/Text/HomerOdyssey 19 .html
http://www.theoi.com/Text/HomerOdyssey 20 .html
http://www.theoi.com/Text/HomerOdyssey 21 .html
http://www.theoi.com/Text/HomerOdyssey 22 .html
http://www.theoi.com/Text/HomerOdyssey 23 .html
http://www.theoi.com/Text/HomerOdyssey 24 .html
>>>
我可以将该输出粘贴到一个新文件中,删除空格,然后使用wget -i
.
但我厌倦了 Python。
我想学习 Haskell。
尽管花了 10 分钟试图从 开始做同样的事情ghci
,但我没有进一步前进。
这就是我的尝试的样子:
alec@ROOROO:~/oldio$ ghci
GHCi, version 7.0.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> putStrLn
<interactive>:1:1:
No instance for (Show (String -> IO ()))
arising from a use of `print'
Possible fix:
add an instance declaration for (Show (String -> IO ()))
In a stmt of an interactive GHCi command: print it
Prelude> putStrLn "hey"
hey
Prelude> putStrLn "hey" [1..10]
<interactive>:1:1:
The function `putStrLn' is applied to two arguments,
but its type `String -> IO ()' has only one
In the expression: putStrLn "hey" [1 .. 10]
In an equation for `it': it = putStrLn "hey" [1 .. 10]
Prelude> putStrLn "hey" snd [1..10]
<interactive>:1:1:
The function `putStrLn' is applied to three arguments,
but its type `String -> IO ()' has only one
In the expression: putStrLn "hey" snd [1 .. 10]
In an equation for `it': it = putStrLn "hey" snd [1 .. 10]
Prelude> putStrLn "hey" $ snd [1..10]
<interactive>:1:1:
The first argument of ($) takes one argument,
but its type `IO ()' has none
In the expression: putStrLn "hey" $ snd [1 .. 10]
In an equation for `it': it = putStrLn "hey" $ snd [1 .. 10]
Prelude> "hello"
"hello"
Prelude> "hello" ++ "world"
"helloworld"
Prelude> "hello" ++ [1..10] ++ " world"
<interactive>:1:16:
No instance for (Num Char)
arising from the literal `10'
Possible fix: add an instance declaration for (Num Char)
In the expression: 10
In the first argument of `(++)', namely `[1 .. 10]'
In the second argument of `(++)', namely `[1 .. 10] ++ " world"'
Prelude> "hello" ++ print [1..10] ++ " world"
<interactive>:1:12:
Couldn't match expected type `[Char]' with actual type `IO ()'
In the return type of a call of `print'
In the first argument of `(++)', namely `print [1 .. 10]'
In the second argument of `(++)', namely
`print [1 .. 10] ++ " world"'
Prelude> print [1..10]
[1,2,3,4,5,6,7,8,9,10]
Prelude> map ("hello") [1..10]
<interactive>:1:6:
Couldn't match expected type `a0 -> b0' with actual type `[Char]'
In the first argument of `map', namely `("hello")'
In the expression: map ("hello") [1 .. 10]
In an equation for `it': it = map ("hello") [1 .. 10]
Prelude> greeting :: String --> Int -> [String, Int]
<interactive>:1:39: parse error on input `,'
Prelude> greeting :: String --> Int -> [(String), (Int)]
<interactive>:1:41: parse error on input `,'
Prelude> greeting :: String -> Int -> [(String), (Int)]
<interactive>:1:40: parse error on input `,'
Prelude> greeting :: String -> Int -> [(String) (Int)]
<interactive>:1:1: Not in scope: `greeting'
Prelude> foreach [1..24] print
<interactive>:1:1: Not in scope: `foreach'
Prelude> import Data.IORef
Prelude Data.IORef> foreach [1..24] print
<interactive>:1:1: Not in scope: `foreach'
Prelude Data.IORef> foreach = flip mapM_
<interactive>:1:9: parse error on input `='