Skip to content

Commit 8287430

Browse files
committed
Add haskell basics
1 parent 3d5a2d8 commit 8287430

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

haskell/basics.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
head [1, 2, 3, 4, 5] -- get the first: 1
2+
tail [1, 2, 3, 4, 5] -- get the last: 5
3+
take 3 [1, 2, 3, 4, 5] -- get the first n elements: [1, 2, 3]
4+
drop 3 [1, 2, 3, 4, 5] -- remove the first n element: [4, 5]
5+
length [1, 2, 3, 4, 5] -- 5
6+
sum [1, 2, 3, 4, 5] -- sum all elements in the list: 15
7+
product [1, 2, 3, 4, 5] -- product all elements in the list: 120
8+
[1, 2, 3] ++ [4, 5] -- append two lists: [1, 2, 3, 4, 5]
9+
reverse [1, 2, 3, 4, 5] -- reverse all elements in the list: [5, 4, 3, 2, 1]

0 commit comments

Comments
 (0)