# Parser combinator in Typed Racket: how to define the type constructor for the parser?

**URL:** <https://racket.discourse.group/t/parser-combinator-in-typed-racket-how-to-define-the-type-constructor-for-the-parser/2909>\
**Category:** Questions & Answers\
**Tags:** typed-racket\
**Created:** [May 7, 2024, 2:17pm UTC](https://racket.discourse.group/t/parser-combinator-in-typed-racket-how-to-define-the-type-constructor-for-the-parser/2909 "2024-05-07T14:17:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yossarian](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@yossarian](https://racket.discourse.group/u/yossarian)\
**Post date:** [May 7, 2024, 2:17pm UTC](https://racket.discourse.group/t/parser-combinator-in-typed-racket-how-to-define-the-type-constructor-for-the-parser/2909/1 "2024-05-07T14:17:56Z")

</div>

I am trying to translate the nice Haskell [tutorial](https://smunix.github.io/dev.stephendiehl.com/fun/002_parsers.html) by Stephen Diehl on parser combinators in Typed Racket. However, I am already stuck when trying to define the parametric Parser type.

Haskell: `newtype Parser a = Parser { parse :: String -> [(a,String)] }`

Racket: `(struct (a) Parser ([parse : (-> String (Listof (Values a String)))]))`

leads to the error "type name `Values' is unbound" (REPL). The main issue seems to be the tuple definition: neither values or Values works ...

Any suggestions?

---

<div class="post-metadata">

**Author:** ![scolobb](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/scolobb/32/108_2.png) [@scolobb](https://racket.discourse.group/u/scolobb)\
**Post date:** [May 7, 2024, 4:06pm UTC](https://racket.discourse.group/t/parser-combinator-in-typed-racket-how-to-define-the-type-constructor-for-the-parser/2909/2 "2024-05-07T16:06:35Z")

</div>

Hi @yossarian,

After a very quick first look I think you should not use `Values` in this context, but rather `Pairof` or `List`. Both of the following typecheck:

```scheme
(struct (a) Parser ([parse : (-> String (Listof (Pairof a String)))]))
(struct (a) Parser ([parse : (-> String (Listof (List a String)))]))

```

The first type is the exact translation of the type in Haskell. For various reasons using a `List` may sometimes be preferable, but I suggest you go with `Pairof` until you find a definite advantage to using `List`.

[`Values`](https://docs.racket-lang.org/ts-reference/type-ref.html#%28form._%28%28lib._typed-racket%2Fbase-env%2Fbase-types-extra..rkt%29._.Values%29%29) allows defining functions returning _multiple values_, which in Racket is different from functions returning pairs, lists or tuples of values.
