haskell - Help In Declaring Variable Number Of Arguments -


high guys,

i have define polymorphic datatype tree can have multiple nodes. each node can have number of children , vlaue. type have @ least 1 node. new in haskell asking how can declare node have variable number of arguments.

this have now. tree can have node or node value (a) , 2 tree children. instead of 2 tree children, want them number of tree children. (analoog java variable number of arguments "arg...")

data tree = node | node (tree a) (tree a) deriving (show) 

thanks help

edit

a little question::: how can declare node variable arguments in functions parameter(header/signature). have implement function called
"contains" check if node contains specific element.

contains :: tree -> b -> bool contains (node val [(tree)]) =   ...... 

is second line correct ?

it be:

data tree = node | node [(tree a)] deriving (show) 

but in addition there second problem should be

data tree = leaf | branch [(tree a)] deriving (show) 

or such parts of union must have different names otherwise couldn't use pattern matching

leaf , branch data constructors so:

branch 1 [leaf 3, branch 6 [leaf 5]] 

is example of tree


contains :: tree -> -> boolean  contains (leaf a) b = == b contains (branch c) b = == b || (map (\t -> contains t b) c) 

or such


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -