I am learning Haskell and was reading through Tying the Knot on how to build a cyclic linked list. In the code
data DList a = DLNode (DList a) a (DList a) mkDList :: [a] -> DList a mkDList  = error "must have at least one element" mkDList xs = let (first,last) = go last xs first in first where go :: DList a -> [a] -> DList a -> (DList a, DList a) go prev  next = (next,prev) go prev (x:xs) next = let this = DLNode prev x rest (rest,last) = go this xs next in (this,last)
I am trying to understand the call where they link the last element to the first through a "little trick" (!) called tying the knot:
mkDList xs = let (first,last) = go last xs first
But I am having difficulty seeing how this works. What is "go" initially called with? And per the comment in the article, how is the first result from "go" "passed back in"?