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

A very beginner's question #1

Expand Messages
  • jartur
    (* Terve! * Why does *) let ht = function el - function il - match il with ... ;; (* work and *) let ht = function el - function il - match il with ... ;;
    Message 1 of 2 , Nov 8, 2004
    • 0 Attachment
      (* Terve!
      * Why does *)

      let ht = function el -> function il -> match il with
      | [] -> []
      | hd::tl -> if el=hd then tl else il
      ;;

      (* work and *)

      let ht = function el -> function il -> match il with
      | [] -> []
      | el::tl -> tl
      | _ -> il
      ;;

      (* doesn't? *)

      (* Kiitos.
      * jartur *)
    • Stephen Gilmore
      The two variables called el are distinct, so the second function is not checking that the list begins with el. You ve got two patterns which match every
      Message 2 of 2 , Nov 8, 2004
      • 0 Attachment
        The two variables called "el" are distinct, so the second function is
        not checking that the list begins with el.
        You've got two patterns which match every list, [] and (el::tl) and so
        O'Caml complains that the third is
        redundant. You need the if..then..else to implement the function that
        you are describing.

        Hope this helps.

        Best wishes,
        Stephen Gilmore

        jartur wrote:

        >(* Terve!
        > * Why does *)
        >
        >let ht = function el -> function il -> match il with
        > | [] -> []
        > | hd::tl -> if el=hd then tl else il
        >;;
        >
        >(* work and *)
        >
        >let ht = function el -> function il -> match il with
        > | [] -> []
        > | el::tl -> tl
        > | _ -> il
        >;;
        >
        >(* doesn't? *)
        >
        >(* Kiitos.
        > * jartur *)
        >
        >
        >
        >
        >
        >
        >Archives up to September 30, 2004 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
        >
        >
        >
        >
        >
        >
        >
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.