Created
April 20, 2011 12:18
-
-
Save JakubOboza/931164 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 |
This file contains hidden or 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
-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