18

Why is there an r in Data.List.unfoldr? Is it only for symmetry with foldr, or is there some other reason this unfolds should be considered to be right associative?

This came up when I was considering adding an unfold to Data.HashMap, where I couldn't think of a reason to include an r in the name. HashMaps have both right and left folds. I don't see a reason why the unfold would be more right than left.

tibbe
  • 8,809
  • 7
  • 36
  • 64
  • 3
    You could imagine an `unfoldl` that builds the list the other order. But which should be `l` or `r` is unclear to me. :) – augustss May 21 '14 at 10:05

1 Answers1

14

In "The Underappreciated Unfold", where unfoldr is introduced, it is known as unfold (and foldr is fold, as you see here). However, by the time it made it into the List library, it had become unfoldr, as a dual to foldr.

Community
  • 1
  • 1
Don Stewart
  • 137,316
  • 36
  • 365
  • 468
  • 2
    This paper now at: [The Under-Appreciated Unfold](http://www.cs.ox.ac.uk/jeremy.gibbons/publications/unfold.ps.gz) – andro Jan 02 '15 at 01:35