[clean-list] unique arrays in unique records
valery at freesurf.fr
valery at freesurf.fr
Fri Mar 31 17:19:29 MEST 2006
I am struggling with uniqueness typing (again).
My goal is ultimately to write a search algorithm (alpha-beta, etc.) for a
board game. Since the board is only slightly altered by each move, I dont
want to allocate a full board each time, so it is unique.
The state of the search is stored in a unique record, which contains,
among other things, a unique array representing the board. My attemp to
update the array is bellow (function seek), but it is rejected :
Uniqueness error [knight.icl,13,seek]: "board" demanded attribute cannot
be offered by shared object
How to update a unique array in a record ?
Start = solutions 2
:: Board :== {#Int}
:: *Seeker = { board :: *Board, wanted :: !Int, found :: [Board]}
solutions :: Int -> [Board]
solutions n = (foldl seek seeker moves).found
where
seek :: Seeker Int -> Seeker // line 13 is here
seek s=:{wanted=0} _ = s
seek s=:{board = b, wanted = w, found = f} i
= { s
& board = { b & [i] = w }
, wanted = w - 1
, found = [{b.[i] \\ i <-: b} : f]
}
seeker = { board = {i \\ i <- [0 .. n * n - 1]}, wanted = 0, found
= [] }
moves = [0..n]
More information about the clean-list
mailing list