Re: pattern matching
"'Mr. Herr' [email protected] [ocaml_beginners]" <[email protected]> Tue, 29 Mar 2016 11:02:40 +0200
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
sorry, overlooked sub matching. You can match several elements in one pattern, just take care to have the "shorter" cases first. | [] -> | head :: [] -> (* equivalent to [head], all list patterns can be written with square brackets *) | head :: second :: rest -> (* here rest can be [] *) This sounds like you did not understand the explanations I gave. /Str. On 29.03.2016 10:18, 'Mr. Herr' [email protected] [ocaml_beginners] wrote: > > > > > On 29.03.2016 06:41, Douglas Lewit [email protected] [ocaml_beginners] wrote: >> >> I also gave something like this a try, but I ended up with a couple of error >> messages: >> >> */let pack list = match list with/* >> */|[ ] -> [ ]/* >> */|head :: tail -> match tail with/* >> */|[ ] -> [ ]/* >> */headOfTail :: tailOfTail -> if head = headOfTail then..... ( more code )/* >> */ >> /* >> I thought it was clever, but either I just ended up with an empty list, a >> one-element list, or the compiler just rejected it. I'm starting to feel a little >> dumb! But I'll keep at it. >> > tailOfTail is a list, not an element! > > /Str. >