Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Pattern Matching
@ 1996-09-05 17:19 Ernesto Posse
  1996-09-06  8:17 ` Pierre Weis
  1996-09-06  9:20 ` Frank Christoph
  0 siblings, 2 replies; 5+ messages in thread
From: Ernesto Posse @ 1996-09-05 17:19 UTC (permalink / raw)
  To: Caml List


Hello everyone.

I have a question about pattern matching. I need a function which 
binds an identifier to a value in certain data structure (which is
called "heap" here). This is actually a (string * record) list. It is
not suppose to be a mutable data structure, so the binding just creates
a
new list copying the same values as the old one with the exception of
the
record to be changed. For this purpose I am using List.map (I am using
O'Caml 1.01 for Windows 95):

let assign heap id obj = 
  List.map
    ( function 
        (id,{ vartype = vt; contents = v; 
              constraints = c; dependencies = d }) -> 
            (id,{ vartype = vt; contents = obj; 
                  constraints = c; dependencies = d })
      | r -> r )    (* 1 *)
    heap

However the compiler tells me that line marked (* 1 *) is an unused case
of the match expression. I thought that maybe the problem was that the
inner id variables (the ones in the function passed to map) are
identifier
patterns therefor they are different from the parameter of the assign
function. So I tried to fix it like this:

let assign heap id obj = 
  List.map
    ( function 
        (name,{ vartype = vt; contents = v; 
                constraints = c; dependencies = d }) 
          when name = id -> 
            (name,{ vartype = vt; contents = obj; 
                    constraints = c; dependencies = d })
      | (name,_) as r when name <> id -> r )
    heap

And now I get the warning "this pattern-matching is not exhaustive".

Can anyone tell me what is wrong with this possibilities and how could
I solve the problem ?  

Thank you very much.

-- 
Ernesto Posse
Estudiante de Ingenieria de Sistemas y Computacion
(Systems and Computing Engineering student)
Universidad de los Andes
Santafe de Bogota
Colombia
e-mail: e-posse@uniandes.edu.co




^ permalink raw reply	[flat|nested] 5+ messages in thread
* stderr
@ 1997-05-01 13:34 David Monniaux
  1997-05-06 14:03 ` pattern matching Olivier Montanuy
  0 siblings, 1 reply; 5+ messages in thread
From: David Monniaux @ 1997-05-01 13:34 UTC (permalink / raw)
  To: Caml-list

Bonjour,

deux petites remarques en passant:

Contrairement aux usages habituels sur Unix pour les compilateurs, ocamlc
sort ses erreurs sur stdout et non stderr. Ce n'est pas bien grave, a part
que cela met les warnings au debut de la sortie demandee par -i (qui,
elle, devrait rester sur stdout).

Par ailleurs, il arrive quelquefois que l'on fasse volontairement des
pattern-matching incomplets, parce que le programme est tel que les cas
non fournis ne peuvent arriver. ocamlc produit une warning dans ce cas, ce
qui d'ailleurs aide largement a eviter des erreurs de programmation.
Le probleme est que lorsque l'on utilise cette facilite de "warnings" pour
detecter des cas "oublies", on est "parasite" par les pattern-matching
incomplets tout a fait normaux que l'on a laisses. De meme que certains
compilateurs C acceptent des #pragma supprimant un certain avertissement
une fois, que l'on place avant un endroit où l'on a fait volontairement
une construction declenchant cet avertissemment, afin de n'etre pas
derange apres, serait-il possible de mettre un tel systeme dans ocaml?

-- David

"Si l'informatique marchait, cela se saurait."
Computer science student at ENS, Lyon, France
http://www.ens-lyon.fr/~dmonniau






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

end of thread, other threads:[~1997-05-07  9:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-09-05 17:19 Pattern Matching Ernesto Posse
1996-09-06  8:17 ` Pierre Weis
1996-09-06  9:20 ` Frank Christoph
1997-05-01 13:34 stderr David Monniaux
1997-05-06 14:03 ` pattern matching Olivier Montanuy
1997-05-06 19:59   ` Stefan Monnier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox