reset password
Author Message
turtl3
Posts: 3
Posted 19:32 Oct 22, 2012 |

I'm having a little trouble understanding the difference between:

case Nil => ???
case _ :: Nil => ???

From the wiki page I see that "Underscore ( _ ) in a pattern means that the expression on the right of => doesn't refer to that part of the pattern"

So if ( _ ) isn't referred to by the expression on the right then wouldn't that just mean a case Nil again? Or am I misunderstanding what ( _ ) represents in case _ :: Nil => ???

rabbott
Posts: 1649
Posted 20:06 Oct 22, 2012 |

 

 

case Nil => ???           // The expression to the left of => is the empty list.
case _ :: Nil => ???      // The expression to the left of => is a singleton list,
                          // but we don't care what the singleton element is.
turtl3
Posts: 3
Posted 20:11 Oct 22, 2012 |

Oh I see. Okay thank you.