Random set of integers

I am trying to use random-extra to generate a set of unique integers, but I am doing something wrong. Probably a beginners mistake or misunderstanding of randomness in Elm, but I cannot figure it out.

The code I wrote is:

import Random exposing (…)
import Random.Set exposing (…)

fillStack : Cmd Msg
fillStack =
Random.generate FillStack generateStack

generateStack : Random.Generator (Set Int)
generateStack =
Random.Set.set 5 (int 1 15)

The compiler says:

– TYPE MISMATCH —

The 2nd argument to generate is not what I expect:

112| Random.generate FillStack generateStack
^^^^^^^^^^^^^
This generateStack value is a:

Generator (Set Int)

But generate needs the 2nd argument to be:

Generator (List Int)

I get the type mismatch, but have no idea how to solve it. I tried to sneak in a Set.toList somewhere, but that was not accepted.

Any help appreciated!

You most likely used type Msg = FillStack (List Int) instead of type Msg = FillStack (Set Int).

Thanks! Just the little push I needed to continue.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.