3 ms·
Haskell doubly linked list: data DLList a = DLList a (DLList a) (DLList a) | End make_dllist :: [a] -> DLList a make_dllist = go (\_ -> End)
by anon291 3y ago
Haskell doubly linked list:
data DLList a = DLList a (DLList a) (DLList a) | End
make_dllist :: [a] -> DLList a
make_dllist = go (\_ -> End)
where go mkPrev [] = mkPrev End
go mkPrev (x:xs) = go (\next -> let me = DLList x (mkPrev me) next in me) xs
No need for IORef. Too many people misunderstand the meaning of 'let' in Haskell. It doesn't mean what you think it does. It defines, not assigns. In rust, let 'declares' and assigns in one go. It does not define.