0

I have this code in SMLNJ:

val reduce = fn : C list -> C list * int

datatype C =  R | G | B | Y | SR | SG | SB | SY | DR | DG | DB | DY | P | W | W';

fun exhaustiveReduce(cList)=
    let
        fun helper((cList, score), prevScore, flag)=
            if (0 = score andalso flag = true) then
                (cList,prevScore)
            else
                helper(reduce(cList), prevScore+score, true)
    in
        helper((cList, 0), 0, false)
    end

When I try to run the following line:

exhaustiveReduce ([B,B,B,G,G,G,G,Y,R,R,R,Y,Y,G,G,G])

I get this error: enter image description here

I understand that the meaning is that I'm trying to send to the function an argument that it doesn't expect to get, but what does the ?. mean? how can I fix it?

P.S. I looked here:What does 'int ?. tree' mean in an SML error message? but didn't find it very useful.

Thanks

Community
  • 1
  • 1
user265732
  • 585
  • 4
  • 14

1 Answers1

1

The ?.t indicates that t has gone out of scope somehow, e.g. because it has been shadowed by a new definition (even if identical). You probably have entered a definition for type C multiple times into the REPL, and your reduce function still refers to an older definition. Simply reenter all definitions dependent on C as well (or use the SML/NJ's compilation manager if you want to do more serious development).

PS: flag = true is equivalent to just saying flag.

Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72