Re: Re: How can we rewrite pattern matching
Francois Berenger <[email protected]>
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
I understand pattern matching as a way to do
type-driven programming.
If then else are to do data-driven programming.
Some may give more litterate answers to your question
however (I expect Gabriel Scherer here, maybe). ;-)
And, maybe you are just looking for the following function:
let is_XType = function
| XType _ -> true
| _ -> false
Then you could do:
if ( is_XType input ) then myFun x
On 10/24/2013 01:56 PM, Aydin Atay wrote:
> Hi everyone, thanks for the replies. I certainly agree that pattern
> matching here is the most elegant solution, but I have a reason for
> asking this question too.
>
> Here's a more precise definition of my question:
>
> I have this: 'input' is peeked from a stream, and XType is a type I
> defined previously. So when input matches my XType I produce myFun
> using x as an argument (which is in scope):
>
> match input with
> XType(a) -> myFun x
>
> If I write this in a if-then-else
>
> if ( ??? == ??? ) then myFun x
>
>
--
Best regards,
Francois Berenger.
------------------------------------
Archives up to December 31, 2011 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners
The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid flames etc.Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ocaml_beginners/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ocaml_beginners/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://info.yahoo.com/legal/us/yahoo/utos/terms/