You're misinterpreting what ()
means in Haskell. It isn't the lack of a value, it is rather the only value of the Unit type (the type itself being referred to by an empty set of parentheses ()
).
Since lambdas can be constructed to use pattern matching, the lambda expression \() -> "s"
is explicitly saying "create an anonymous function, expecting an input that matches the ()
pattern". There isn't much point to doing it, but it's certainly allowed.
You can use pattern matching with lambdas in other ways as well, for example:
map (\(a, b) -> a + b) [(1,2), (3,4), (5,6)] -- uses pattern matching to deconstructdestructured eachtuples
map tuple(\(Name first _) -> first) [Name "John" "Smith", Name "Jane" "Doe"] -- matches a "Name" data type and its first field
map (\(x:_) -> x) [[1,2,3], [4,5,6]] -- matches the head of a list