Hello Haskellers and Haskellettes,
when reading http://learnyouahaskell.com/ a friend of mine came up with a problem:
Is it possible in Haskell to write a recursive function that gives True if all sub-sub-_-sublists are empty. My first guess was - should be - but i have a big problem just writing the type annotation.
he tried something like
nullRec l = if null l
then True
else if [] `elem` l
then nullRec (head [l]) && nullRec (tail l)
else False
which is - not working - :-)
i came up with something like
- folding with concat - to get a a single long list
(giving me problems implementing) - or making an infinite treelike datatype - and making this from the list
(haven't implemented yet)
but the latter sound a bit like overkill for this problem. what is your ideas - on a sunny sunday like this ;-)
Thanks in advance
as a reaction to all the comments - this being bad style i'd like to add
this is just an experiment!
DO not try this at home! ;-)
nullRec2 :: [[a]] -> Bool,nullRec3 :: [[[a]]] -> Booland so on (try a couple!), but you can't get them to fit a single type signature easily. You either need a tree type likedata Tree a = Branch [Tree a] | Node aor maybe there's something possible with typeclasses (haven't thought much about this approach yet).nullRec [""]andnullRec [empty :: ByteString]should be. You shall see that there is no good answer.