gkz / prelude-ls

prelude.ls is a functionally oriented utility library - powerful and flexible, almost all of functions are curried. It is written in, and is the recommended base library for, http://livescript.net
http://preludels.com/
MIT License
424 stars 57 forks source link

scan1/scanl1 undefined for empty list #95

Open atifaziz opened 9 years ago

atifaziz commented 9 years ago

Is that any particular reason why scan1/scanl1 returns void when the input is an empty list? Why not just return an empty list instead?

anko commented 9 years ago

scan is basically a verbose fold, and fold requires an initial value by its definition.

homam commented 9 years ago

I think it should be an empty array.

scanl1 :: (a -> a -> a) -> [a] -> [a]

Empty array fits the expected type.

igl commented 9 years ago

i rather have undefined for failed operations because a empty array is not falsy.

it's [a] not []. and therefor undefined behavior.

atifaziz commented 9 years ago

@anko scanl1 in Haskell returns an empty list and so do many other implementations, which is what prompted me to open this issue. fold has a different problem. It aggregates to a single result therefore it's understandable that its result is undefined if there's no seed. In the case of scan1 if there's no seed then there are no intermediate computations to report and an empty list would be a reasonable answer.

@igl If it always returns a list then your falsy test just goes against its length instead.