Computer Science Canada pattern matching issue |
Author: | Fonzie [ Mon Mar 02, 2009 6:48 pm ] | ||
Post subject: | pattern matching issue | ||
How do I match a pattern without assigning the variable I'm matching a new value? For example Let's say I want to make sure t is of the form Node (i,t1,t2), but then I want to leave t alone and do something else. So I guess I'm looking for a kind of if statement that can match patterns.
Is this possible? |
Author: | wtd [ Mon Mar 02, 2009 7:12 pm ] |
Post subject: | RE:pattern matching issue |
Language? |
Author: | Fonzie [ Mon Mar 02, 2009 7:26 pm ] |
Post subject: | Re: pattern matching issue |
ocaml |
Author: | wtd [ Mon Mar 02, 2009 7:33 pm ] | ||
Post subject: | RE:pattern matching issue | ||
|
Author: | Fonzie [ Mon Mar 02, 2009 7:48 pm ] |
Post subject: | Re: pattern matching issue |
my problem with that though is that t is then assigned the value of blah(). I'm trying to find a way so that t is not assigned a new value. |
Author: | wtd [ Mon Mar 02, 2009 7:57 pm ] | ||
Post subject: | RE:pattern matching issue | ||
|
Author: | Fonzie [ Mon Mar 02, 2009 8:14 pm ] | ||
Post subject: | Re: pattern matching issue | ||
But then can I use it as I previously mentioned? Let me show you in pseudo code what I'm trying to do.
I'm trying to Identify what type t is and take different steps depending on the type. |
Author: | wtd [ Mon Mar 02, 2009 8:28 pm ] | ||
Post subject: | RE:pattern matching issue | ||
|
Author: | Fonzie [ Mon Mar 02, 2009 8:51 pm ] | ||
Post subject: | Re: pattern matching issue | ||
I think I've perhaps been communicating something wrong. Thank you for your patience and help up to this point. Here is my actual function.
I'm getting type complaints from the compiler because sum and loop(t,0::(3::instructions), sum+i, t1) are different types I think. I'm just trying to find a way to verify type without getting complaints. |
Author: | wtd [ Mon Mar 02, 2009 9:54 pm ] |
Post subject: | RE:pattern matching issue |
Can you provide the type declaration? |
Author: | Fonzie [ Mon Mar 02, 2009 10:04 pm ] | ||
Post subject: | Re: pattern matching issue | ||
sure thing
|
Author: | wtd [ Mon Mar 02, 2009 10:36 pm ] | ||
Post subject: | RE:pattern matching issue | ||
First off, let's format that nicely. Just because O'Caml has free-form syntax doesn't mean we need to be sloppy.
I've also added some type annotations to aid in figuring out where this is breaking. |
Author: | wtd [ Mon Mar 02, 2009 11:04 pm ] | ||
Post subject: | RE:pattern matching issue | ||
Oops.
|
Author: | Fonzie [ Tue Mar 03, 2009 8:20 pm ] |
Post subject: | Re: pattern matching issue |
Alright, thank you very much for all the help you've given me. |
Author: | wtd [ Tue Mar 03, 2009 9:00 pm ] | ||
Post subject: | RE:pattern matching issue | ||
For what it's worth, a little bit different syntactic take on things.
|