0

I am trying to create a list of lists meaning my result should be like

thatgraph = [[0,[1,2]],[1,[1,3],[1,4],[1,5]],[2,[3,4],[4,4],[5,5],[5,10]]

The code i use is :

 fun pin2graph (pin,thatgraph,i,j,rows,cols,havepizza) =

if (i<rows) andalso (j<cols-1) then   
        (
         pin2graph (pin,thatgraph::((i*cols+j),(getAdjacent (pin,i,j,rows,cols,havepizza))),i,j+1,rows,cols,havepizza)
        )
        else if (i<rows)  then
        (
        pin2graph (pin,thatgraph::((i*cols+j),(getAdjacent (pin,i,j,rows,cols,havepizza))),i+1,0,rows,cols,havepizza)
        )
        else thatgraph 

The getadjacent function is of type :

val getAdjacent = fn
  : char Array2.array * int * int * int * int * 'a -> (int * 'a) list

the 'a is actually a real number so the real type is (int * real) list .

Whatever i have tried i always get an operand and operator mismatch with most common being :

 operator domain: _ * _ list
 operand:         _ * (int * (int * 'Z) list)

Any hint would be greatly appreciated , running out of ideas

Akismpa
  • 61
  • 7
  • 1
    `thatgraph` doesn't have a valid type. e.g. the first item `[0,[1,2]]` has both an `int` and an `int list` as elements. There is no type (afaik) that is both an `int` and an `int list`, so you can't have a list of this nonexistent type. – Alejandro C. May 16 '17 at 15:52
  • It is possible to use *tuples* of type `int * (int list list)` which could include values like `(0, [[1,2]])` and `(1,[[1,3],[1,4],[1,5]])`. You can of course create lists of such tuples. That is the closest you can come in SML to what you are trying to do. – John Coleman May 17 '17 at 08:26

0 Answers0