Inspired by this article. I played with translation functions from list comprehension to combinational style. I found something interesting.
-- Example 1: List Comprehension *Main> [x|(x:_)<-["hi","hello",""]] "hh" -- Example 2: Combinatory *Main> map head ["hi","hello",""] "hh*** Exception: Prelude.head: empty list -- Example 3: List Comprehension (translated from Example 2) *Main> [head xs|xs<-["hi","hello",""]] "hh*** Exception: Prelude.head: empty list
It seems strange that Example 1 does not throw an exception because the pattern (x:_) matches one of the definitions of head . Is there an implied filter (not . null) when using lists?
exception haskell list-comprehension
user295190
source share