Skip to content

Instantly share code, notes, and snippets.

@nietaki
Created February 13, 2012 16:43
Show Gist options
  • Save nietaki/1818076 to your computer and use it in GitHub Desktop.
Save nietaki/1818076 to your computer and use it in GitHub Desktop.
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