Well, I asked Dani and she said I could create a Haskell catagory in code snippits just by submitting a Haskell program :p . What self respecting code repository would be without one? So here goes, this program calculates the nth triangular number, given n by the user.


module Main

result x = foldr (+) 0 [1..read x]

main = do
putStrLn("Your input: ")
user_data <- getLine
putStrLn("My output: ")
print(result user_data)

Interesting, how do you run this program?

It's not good form to put the body of a 'do' block (or any other artifact) on the first row. It's probably illegal, and although GHC accepts the syntax, it won't let you put any more top-level definitions in the file.

Oh, and to run this program, type 'ghc --make foo.hs' (where foo.hs is your actual filename) to compile and then run the program foo. You'll need to get GHC though.