[clean-list] uniqueness error

valery at freesurf.fr valery at freesurf.fr
Fri Jun 16 10:31:24 MEST 2006


Hello,

The program below is supposed to solve the knight's tour problem without
any array copying, the last obstacle beeing an uniqueness error I can't
solve (Uniqueness error [knight.icl,16,seek]: "board" demanded attribute
cannot be offered by shared object). I'm pretty sure that the error is
caused by the definition of the "moves" list in the middle of "seek".

I tried to use strict lists, so that "moves" is build entirely
before "board" is modified by "foldl", but got a different error (Type
error [knight.icl,22,comprehension]: cannot unify [(Int,Int)] with [!
(Int,Int)!]). Where is the mismatch ?

-- Valery

module knight

import StdEnv

Start = solutions 3

:: *Board :== {#Int}
:: *Seeker = {board :: Board, level :: !Int, found :: !Bool, counter :: !
Int}

solutions :: !Int -> Seeker
solutions n = seek seeker (0,0)
where
	seeker = {board = {0 \\ i <- [0 .. n*n - 1]}, level = n * n, found
= False, counter = 0}
	index (x,y) = x + n * y
	isFree (x,y) b = x >= 0 && x < n && y >= 0 && y < n && b.[index
(x,y)] == 0
	seek s=:{found = True} _ = s
	seek s=:{level = 0}    _ = {s & found = True}
	seek s (x,y)
	# counter = s.counter
	# level = s.level + 1
	# board = {s.board & [index (x,y)] = s.level}
	# moves = [p \\ (dx,dy) <- jumps , let p = (x+dx,y+dy)
		| isFree p board]
	# s = {s & board = board, level = level - 1, counter = counter}
	# s = foldl seek s moves
	| s.found = s
	| otherwise
		# board = {s.board & [index (x,y)] = 0}
		= {s & board = board, level = level}
jumps =: [(-1,2),(-2,1),(-2,-1),(-1,-2),(1,-2),(2,-1),(2,1),(1,2)]





More information about the clean-list mailing list