* [Caml-list] Case insensitive in type
@ 2014-07-02 8:34 Nicolas Ratier
2014-07-02 8:43 ` Daniel Bünzli
0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Ratier @ 2014-07-02 8:34 UTC (permalink / raw)
To: caml-list
Hello,
We use the type :
type term =
| Term of string * term list
| Var of string * int
;;
I would like the string of the Term constructor not to be case sensitive,
for example, all the following terms should be the same :
Term("Plus",[...])
Term("plus",[...])
Term("PLUs",[...])
Is it possible ?
Thanks,
Nicolas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Case insensitive in type
2014-07-02 8:34 [Caml-list] Case insensitive in type Nicolas Ratier
@ 2014-07-02 8:43 ` Daniel Bünzli
2014-07-02 9:30 ` Gabriel Kerneis
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Bünzli @ 2014-07-02 8:43 UTC (permalink / raw)
To: Nicolas Ratier; +Cc: caml-list
Le mercredi, 2 juillet 2014 à 09:34, Nicolas Ratier a écrit :
> I would like the string of the Term constructor not to be case sensitive,
> for example, all the following terms should be the same :
[...]
> Is it possible ?
The only way to do this is to make the type private and always construct term values through a constructor which normalizes the strings.
type term = private Term of string * term list
let term s args = Term ((String.lowercase s), args)
Best,
Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Case insensitive in type
2014-07-02 8:43 ` Daniel Bünzli
@ 2014-07-02 9:30 ` Gabriel Kerneis
2014-07-02 9:43 ` Daniel Bünzli
0 siblings, 1 reply; 4+ messages in thread
From: Gabriel Kerneis @ 2014-07-02 9:30 UTC (permalink / raw)
To: Daniel Bünzli; +Cc: Nicolas Ratier, caml-list
On Wed, Jul 02, 2014 at 09:43:13AM +0100, Daniel Bünzli wrote:
> Le mercredi, 2 juillet 2014 à 09:34, Nicolas Ratier a écrit :
> > I would like the string of the Term constructor not to be case sensitive,
> > for example, all the following terms should be the same :
>
> [...]
> > Is it possible ?
>
> The only way to do this is to make the type private and always
> construct term values through a constructor which normalizes the
> strings.
>
> type term = private Term of string * term list
> let term s args = Term ((String.lowercase s), args)
It will not help with pattern-matching, though. The following will fail:
match (term "plus" []) with
| Term("Plus",[]) -> true
| _ -> assert false
I don't think there is a way to work around this.
--
Gabriel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Case insensitive in type
2014-07-02 9:30 ` Gabriel Kerneis
@ 2014-07-02 9:43 ` Daniel Bünzli
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Bünzli @ 2014-07-02 9:43 UTC (permalink / raw)
To: Gabriel Kerneis; +Cc: Nicolas Ratier, caml-list
Le mercredi, 2 juillet 2014 à 10:30, Gabriel Kerneis a écrit :
> It will not help with pattern-matching, though. The following will fail:
>
> match (term "plus" []) with
> | Term("Plus",[]) -> true
> | _ -> assert false
>
> I don't think there is a way to work around this.
Yeah sure, the pattern matches you write have to follow the normalization. A work around is to make the string abstract and then check via a when clause.
match (term "plus" []) with
| Term (f, []) when f = Term.name "Plus" -> true
| _ -> assert false
Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-02 9:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-02 8:34 [Caml-list] Case insensitive in type Nicolas Ratier
2014-07-02 8:43 ` Daniel Bünzli
2014-07-02 9:30 ` Gabriel Kerneis
2014-07-02 9:43 ` Daniel Bünzli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox