Created
February 13, 2012 16:43
-
-
Save nietaki/1818076 to your computer and use it in GitHub Desktop.
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
mylen [] = 0 | |
myhead (h:t) = h | |
myhead [] = error "nie mozna na pustej liscie" | |
mytail (h:t) = t | |
infixl 6 +++ | |
[] +++ y = y | |
(h:t) +++ y = h:(t +++ y) | |
mytake 0 ls = [] | |
mytake quantity [] = [] | |
mytake quantity (h:t) = h: (mytake (quantity - 1) t) | |
inits [] = [[]] | |
inits (h:t) = [] : [ (h:x) | x <- inits t] | |
partitions [] = [([], [])] | |
partitions ls = subpartitions 0 ls | |
-- operator : po lewej stronie ma mieć ELEMENT a po prawej LISTĘ ELEMENTÓW | |
subpartitions x ls = | |
if x < length ls then | |
(take x ls, drop x ls) : subpartitions (x+1) ls | |
else | |
[(ls, [])] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment