Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created April 20, 2011 12:18
Show Gist options
  • Save JakubOboza/931164 to your computer and use it in GitHub Desktop.
Save JakubOboza/931164 to your computer and use it in GitHub Desktop.
mapList foo (h:hs) = foo(h):mapList foo hs
mapList foo [] = []
-- last pattern is empty list
-- no imports / exports needed
-- single var assignment
-- type sefe ? type inference
data BookInfo = Book Int String [String]
deriving (Show)
bookID (Book id _ _ ) = id
bookTitle (Book _ title _ ) = title
bookAuthors (Book _ _ authors) = authors
-- "_" wildcard same as in Erlang
-module(test).
-export([mapList/2]).
mapList(F, [H | T]) -> [ F(H) | mapList(F, T) ];
mapList(F, []) -> [].
% last pattern is empty list
% imports / exports in module
% single var assignment
% usage: fib:mapList(fun(X) -> X+1 end, [1,2,3]). => [2,3,4]
% dynamic typing, type unsafe ?
{book, { _ , Title, _ }} = {book, { 1, "BigOne", ["srsly? ", "yes"]} }.
% same wildcard "_"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment