I have a function named dfs which produces a list of all visited nodes in a graph represented by a list of tuples such as [(node1,node2,weight),....] and I get this error :
v.sml:72.7-79.16 Error: right-hand-side of clause doesn't agree with function result type [circularity]
expression: ''Z -> ''Z list
result type: ''Z list -> ''Z list
in declaration:
find_visited = (fn arg => (fn <pat> => <exp>))
uncaught exception Error
raised at: ../compiler/TopLevel/interact/evalloop.sml:66.19-66.27
../compiler/TopLevel/interact/evalloop.sml:44.55
../compiler/TopLevel/interact/evalloop.sml:292.17-292.20
-
Code :
fun succesors n e =
List.map (fn (_, v, _) => v) (List.filter (fn (u, _, _) => n = u) e)
fun dfs graph start =
let
fun find_visited visited node =
if not (List.exists (fn x => x = node) visited) then
let
val s = (succesors node graph)
in
foldl (fn (v, n) => (find_visited v n)) (node::visited) s
end
else
visited
in
find_visited [] start
end