getting parse error on input '=' error (haskell) -


my function append takes list of lists [[a], [b,c], [d,e]] , returns single list [a,b,c,d,e]. wrote in file didn't have use "let" still parse error on input '='. can help? thanks

append :: [[a]] -> [a] append [[a]] = [ | len = length a, n = 1, head ++ (a !! n) , n < len] 

you need let len , n:

append [[a]] = [a | let len = length a, let n = 1, head ++ (a !! n), n < len] 

but won't solve of problems, once lets added doesn't typecheck, , [[a]] not pattern want use here. pattern [[a]] match list [[1]], won't match [], or [[1, 2]], or [[1], [2]].

you have problem head ++ (a !! n) should expression returns bool, in case it's returning list. "naked" expressions on right side of | in list comprehension must evaluate bool value.

if you're wanting flatten list of lists, suggest looking @ built-in concat function, defined using foldr. folds can tricky learn, though, i'll show alternate definition using explicit recursion:

myconcat :: [[a]] -> [a] myconcat [] = [] myconcat (x:xs) = x ++ myconcat xs 

this equivalent foldr definition, can more instructive how solve sort of problem.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -