Python and Ruby

Paul Rubin no.email at nospam.invalid
Mon Feb 1 01:22:14 EST 2010


Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au> writes:
> How would Haskell coders write it? Something like this?
>
> def get_popular_name(url):
>     data = fetch url
>     names = parse data
>     name = choose name 1
>     return name

The syntax and types would be different, but ok, something like that.

> name = get_popular_name 'http://guessmyname.com'  # call the function
> f = decorate get_popular_name  # treat the function as a 1st class object

You wouldn't need "decorate".  You'd just say

   f = get_popular_name "http://guessmyname.com"

f is now an "I/O action" which when executed queries the guessmyname site.

> but now how do I call the new function?
> Is this where you say "Monads" and everyone's eyes glaze over?

You'd say something like

   most_popular_name <- f

to invoke the action.  Yes, explaining the difference between
"<-" and "=" involves monads.

You might like the Haskell tutorial http://learnyouahaskell.com .



More information about the Python-list mailing list