Skip to content

Instantly share code, notes, and snippets.

View moonmaster9000's full-sized avatar

moonmaster9000 moonmaster9000

View GitHub Profile
c2 = addBook "Garden of Rama" clarke
addAuthor a (Book b as) = Book b ((createAuthor a [b]):as)
addBook b (Author a bs) = Author a ((createBook b [a]):bs)
clarkeBooks = map title $ books clarke
-- ["2001: A Space Odyssey", "Rama!"]
clarke.books.map {|b| b.title}
# ==> ["2001: A Space Odyssey", "Rama!"]
clarke = createAuthor "Arthur C. Clarke" ["2001: A Space Odyssey", "Rama!"]
module Library where
data Author =
Author {
name :: String,
books :: [Book]
} deriving (Show)
data Book =
Book {
clarke = Author.new "Arthur C. Clarke"
odyssey = Book.new "2001: A Space Odyssey"
clarke.books << odyssey
odyssey.authors << clarke
class Author
attr_accessor :name, :books
def initialize(name)
@name = name
@books = []
end
end
class Book
module LineEndingConverter
where
-- splits a string into substrings based on the newlines
-- and handles both windows and unix style line endings
splitLines [] = []
splitLines string = firstLine : remainingLines
where
(firstLine, rest) = break carriageReturnOrLineFeed string
remainingLines =
import System.Environment (getArgs)
import LineEndingConverter
main =
do
args <- getArgs
case args of
[input,output] ->
transformFileWith transformerFunction input output