# Constant string pattern matching

**URL:** <https://discuss.ocaml.org/t/constant-string-pattern-matching/10801>\
**Category:** Learning\
**Tags:** pattern\
**Created:** [November 16, 2022, 12:44am UTC](https://discuss.ocaml.org/t/constant-string-pattern-matching/10801 "2022-11-16T00:44:51Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![nobrowser](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nobrowser/32/2099_2.png) [@nobrowser](https://discuss.ocaml.org/u/nobrowser)\
**Post date:** [November 16, 2022, 12:44am UTC](https://discuss.ocaml.org/t/constant-string-pattern-matching/10801/1 "2022-11-16T00:44:51Z")

</div>

Let’s say I write something like this:

```auto
match lexeme with
| "foo00" -> Foo00
| "foo01" -> Foo01
  ...
| "foo50" -> Foo50
| _ -> FooError

```

(My real keywords are not uniform like this.)  
Does this compile to the obvious straight linear search, or is there any cleverness (like a constant hidden hashtable perhaps)? Or should I have a hashtable myself?

---

_[View the full topic](https://discuss.ocaml.org/t/constant-string-pattern-matching/10801)._
