Loading ...
Sorry, an error occurred while loading the content.

13972Re: "ocaml_beginners"::[] Re: How can we rewrite pattern matching

Expand Messages
  • Francois Berenger
    Oct 23, 2013
      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.
    • Show all 2 messages in this topic