Spice syntax for variants with argument

Hello all, I’m trying to migrate from decco to ppx-spice and I’m wondering how to migrate the following type:

type gameType =
| StandAlone
| Master(string)
| Slave(string)

Can anyone help me?


Okay so I understand from docs/GUIDE.md in https://www.npmjs.com/package/@greenlabs/ppx-spice/v/0.1.15?activeTab=code
that I can use:

// generates the functions gameId_encode() and gameId_decode()
type gameId = string

// generates the functions t_encode() and t_decode()
type t =
  | StandAlone
  | Master(gameId)
  | Slave(gameId)

Then the values with arguments are apparently encoded as arrays:

["Master", "gameId"]

But now that I run the compiler (rescript) I’m getting:

rescript: [178/268] src/modules/GameTypeCodec-Salem1692.cmj
FAILED: src/modules/GameTypeCodec-Salem1692.cmj

  We've found a bug for you!

  The variant constructor Function$ can't be found.

  - If it's defined in another module or file, bring it into scope by:
    - Prefixing it with said module name: TheModule.Function$
    - Or specifying its type: let theValue: TheModule.theType = Function$
  - Constructors and modules are both capitalized. Did you want the latter?
    Then instead of let foo = Bar, try module Foo = Bar.

I’m getting it for every Codec, and I have no idea what this means or how to solve it. Anyone?

Thanks in advance,

I am currently on:

    "@greenlabs/ppx-spice": "^0.1.15",
    "@rescript/react": "^0.11.0",
    "react": "^18.2.0",
    "react-client": "^1.0.1",
    "react-dom": "^18.2.0"
    "rescript": "10.1",

What’s the ppx-flags field in the bsconfg.json?

It was set to this:

  "ppx-flags": [
    ["@greenlabs/ppx-spice/ppx", "-uncurried"]

Removing the “-uncurried” option seems to get me further :grinning: Thanks for pointing me in the right direction!

1 Like