caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* How can I have a string matched my custom type?
@ 2005-05-28 15:46 jeremy
  2007-05-28 16:14 ` [Caml-list] " Jean-Christophe Filliatre
  0 siblings, 1 reply; 5+ messages in thread
From: jeremy @ 2005-05-28 15:46 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1044 bytes --]

hi list, 
    I want to parse an expression string from the command line arguments, and have written some codes like below:
    
    open Printf

    type expr =      
          Plus        of expr * expr
        | Minus     of expr * expr
        | Times     of expr * expr            
        | Divide    of expr * expr
        | Value     of string

    let rec to_string e =
        match e with
              Plus      (left, right)   -> "(" ^ (to_string left) ^ "+" ^ (to_string right) ^ ")"
            | Minus     (left, right)   -> "(" ^ (to_string left) ^ "-" ^ (to_string right) ^ ")"
            | Times     (left, right)   -> "(" ^ (to_string left) ^ "*" ^ (to_string right) ^ ")"
            | Divide    (left, right)   -> "(" ^ (to_string left) ^ "/" ^ (to_string right) ^ ")"
            | Value     v               -> v

    let _ =
         print_endline (to_string Sys.argv.(1))

when I compile it  , It raise an error : 
This expression has type string but is here used with type expr 

How can I solve this problem?  thx .

[-- Attachment #2: Type: text/html, Size: 2536 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-05-28 18:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-28 15:46 How can I have a string matched my custom type? jeremy
2007-05-28 16:14 ` [Caml-list] " Jean-Christophe Filliatre
2007-05-28 17:54   ` Mehdi
2007-05-28 18:07     ` Jean-Christophe Filliatre
2007-05-28 18:23       ` Mehdi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).