Version française
Home     About     Download     Resources     Contact us    
Browse thread
Fragile pattern matching?!
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alex Baretta <alex@b...>
Subject: Re: [Caml-list] Fragile pattern matching?!
Keith Wansbrough wrote:
> Alex Baretta writes:
> 
> 
>>let to_int value = match value with
>>   | Int x -> x
>>   | _ -> raise Some_exception
>>
>>The compiler signals a warning for a fragile pattern matching at the "_" 
>>character.
>>
>>Why in the world should this code signal such a warning?
> 
> 
> The reason is to do with code maintenance.  When in future you add
> another constructor to the value type, the type checker will tell you
> the locations of all matches that have now become incomplete, so that
> you can fix them.  But the match in "to_int" above will never become
> incomplete.  If the type checker passed this silently, then a bug
> could easily be introduced.  Hence the warning.

I understand the need for this kind of warning, but it seems to me that 
I have used the "match x with Something -> do_something x | _ -> 
raise_an_exception" for years. Suddenly, I see the compiler signal 
warnings where I would not expect to seen them.

What is the exact definition of fragile pattern matching?

Alex


-- 
*********************************************************************
http://www.barettadeit.com/
Baretta DE&IT
A division of Baretta SRL

tel. +39 02 370 111 55
fax. +39 02 370 111 54

Our technology:

The Application System/Xcaml (AS/Xcaml)
<http://www.asxcaml.org/>

The FreerP Project
<http://www.freerp.org/>