Questions on type declarations

Hi, Could you comment on the following type declarations? - getArgs :: IO [String] It can get several params, but its type declaration looks like it gets none. - dispatch :: [(String, [String] -> IO ())] [1] I don't know how to read this one. It looks bizarre. [1] http://learnyouahaskell.com/input-and-output#files-and-streams

On Friday, 5 October 2012 at 19:55, thorsopia@lavabit.com wrote:
- getArgs :: IO [String]
It can get several params, but its type declaration looks like it gets none.
It doesn't get any Haskell parameters; it retrieves OS-level (not Haskell-level) parameters to the program. If you know Perl, it's the difference between @_ and @ARGV; if Python, the difference between local parameters and sys.argv. You might infer from the fact that other languages also distinguish, that there is an actual difference between function parameters and program parameters; if you are not clear on this, you will need to figure it out regardless of the language you're working with.
- dispatch :: [(String, [String] -> IO ())] Looks to me like it's described fairly well by the text. What is your confusion?
It is an association list: a list of pairs, the first element being a key and the second being a value. The value in this case is a function which takes a list of strings and produces an IO action. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix/linux, openafs, kerberos, infrastructure http://sinenomine.net Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On 06/10/2012 02:06, brandon s allbery kf8nh wrote:
On Friday, 5 October 2012 at 19:55, thorsopia@lavabit.com wrote:
- getArgs :: IO [String]
It can get several params, but its type declaration looks like it gets none. It doesn't get any Haskell parameters; it retrieves OS-level (not Haskell-level) parameters to the program. If you know Perl, it's the difference between @_ and @ARGV; if Python, the difference between local parameters and sys.argv. You might infer from the fact that other languages also distinguish, that there is an actual difference between function parameters and program parameters; if you are not clear on this, you will need to figure it out regardless of the language you're working with. Perhaps the confusion comes from the fact that languages such as C or Java treat the program parameters as function arguments to main. Position which is not completely non-sensical when calls such as exec() exist, but I'd rather that they divide the OS-level arguments from the language-level ones: they are different after all.
And, judging from its signature, getArgs isn't a function without parameters but a value representing a list of program parameters, possibly empty. Said value coming from the system, it is in IO.
- dispatch :: [(String, [String] -> IO ())] Looks to me like it's described fairly well by the text. What is your confusion?
It is an association list: a list of pairs, the first element being a key and the second being a value. The value in this case is a function which takes a list of strings and produces an IO action.
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix/linux, openafs, kerberos, infrastructure http://sinenomine.net
Sent with Sparrow http://www.sparrowmailapp.com/?sig
participants (3)
-
ARJANEN Loïc Jean David
-
brandon s allbery kf8nh
-
thorsopia@lavabit.com