Skip to content

Instantly share code, notes, and snippets.

@LeifW
Created June 16, 2009 00:58
Show Gist options
  • Save LeifW/130457 to your computer and use it in GitHub Desktop.
Save LeifW/130457 to your computer and use it in GitHub Desktop.
-- Out of curiousity, a take on Igal's language comparison in Haskell http://gist.github.com/126387
-- Goal: Turn Array `["foo", "bar", "baz"]` into String `"ordered: 1=foo 2=bar 3=baz"`.
-- Haskell
-- Read arguments from command line
-- (def argv *command-line-args*)
import Data.List(intercalate)
-- Fake command-line arguments for use in REPL
argv = words "foo bar baz"
result = intercalate " " $ "ordered:" : zipWith (\num word-> show num ++ "=" ++ word) [1..] argv
main = putStrLn result
--Solution 2: Mimic Ruby's each with index:
argv = words "foo bar baz"
map = (\_ _ _ func list ->Prelude.map func $ zip list [1..])
each = undefined
with = undefined
index = undefined
mapM_ putStr $ "ordered:": map each with index (\(word, i)->" " ++ show i ++ "=" ++word) argv
(: XQuery :)
('ordered:', for $item at $pos in ("foo","bar","baz") return concat($pos,'=',$item))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment