<div dir="ltr">In NestedList, the List constructor takes a regular list of NestedLists.  Therefore when pattern matching on it you can get access to those nested lists.  In your code, x is the first NestedList, and xs is the rest of the NestedLists.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 26, 2021 at 4:32 PM Lawrence Bottorff <<a href="mailto:borgauf@gmail.com">borgauf@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I'm following <a href="https://wiki.haskell.org/99_questions/Solutions/7" target="_blank">this</a> and yet I see this solution<div><br></div><div>data NestedList a = Elem a | List [NestedList a] deriving (Show)<br></div><div><br></div><div>flatten1 :: NestedList a -> [a]<br>flatten1 (Elem a   )   = [a]<br>flatten1 (List (x:xs)) = flatten1 x ++ flatten1 (List xs)<br>flatten1 (List [])     = []<br></div><div><br></div><div>What I find puzzling is this line</div><div><br></div><div>flatten1 (List (x:xs)) = flatten1 x ++ flatten1 (List xs)<br></div><div><br></div><div>where I see </div><div><br></div><div>(List (x:xs)) as an argument. How is the NestedList type also able to be expressed as a normal consed list with x:xs argument? How is (:) interacting with NestedList?</div><div><br></div><div>LB</div></div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>