Created
June 16, 2009 00:58
-
-
Save LeifW/130457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(: 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