-ropeStep rope step = rope & headR .~ hr
- & tailR .~ tailR'
- & trace %~ S.insert tailR'
- where hr = (rope ^. headR) ^+^ step
- tr = rope ^. tailR
- tailR' = if tr `touching` hr
- then rope ^. tailR
- else tr ^+^ (tr `towards` hr)
+ropeStep rope step = rope & headK .~ h
+ & knots .~ (reverse kts')
+ & trace %~ S.insert (head kts')
+ where h = (rope ^. headK) ^+^ step
+ kts = rope ^. knots
+ (_, kts') = foldl' knotStep (h, []) kts
+
+
+-- foldl' (f) (hr, []) knots
+
+knotStep (h, ks) kt = (kt', (kt':ks))
+ where kt' = if kt `touching` h
+ then kt
+ else kt ^+^ (kt `towards` h)
+