-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0 parents
commit 0fc3199
Showing
5 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- Find the last element of a list. | ||
|
||
myLast :: [a] -> a | ||
myLast [x] = x | ||
myLast (_:xs) = myLast xs | ||
|
||
main = print (myLast [1..10]) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- Find the last but one element of a list. | ||
|
||
myButLast :: [a] -> a | ||
myButLast [x,y] = x | ||
myButLast (_:xs) = myButLast xs | ||
|
||
main = print (myButLast [1..10]) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- Find the K'th element of a list. The first element in the list is number 1. | ||
|
||
elementAt :: [a] -> Int -> a | ||
elementAt (x:_) 1 = x | ||
elementAt (_:xs) y = elementAt xs (y - 1) | ||
|
||
main = print (elementAt "Haskell" 5) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- Find the number of elements of a list. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.PHONY: all clean | ||
|
||
all: clean | ||
|
||
clean: | ||
find . -type f -not -name '*.hs' -not -name 'Makefile' -not -path './.git/*' | xargs rm -f |