I’m assuming the empty string and the empty array both evaluate to false here and that makes the comparison true? I tried “” == () in perl and that also evaluates true.
Javascript’s === operator would make this false though, correct?
I’m not sure if the OverloadedStrings extension is on by default in the latest version of GHC yet, but with the flag set, string literals become polymorphic types. So
(“” :: Text) == []
(“” :: ByteString) == []
would both result in a type error and would not be evaluated. However:
(“” :: String) == []
would work fine since
type String = [Char]
and (“” == []) has the string literal type default to String, so it would work.
I’m assuming the empty string and the empty array both evaluate to false here and that makes the comparison true? I tried “” == () in perl and that also evaluates true.
Javascript’s === operator would make this false though, correct?
LikeLike
Dave Maez true. 😀
ie: correct
LikeLike
Strings are arrays of characters so … 😁
LikeLike
They are both true for different reasons.
In JavaScript == does type coercion while === doesn’t. The only thing the two objects have in common is Boolean truthiness.
In Haskell strings are treated as arrays of chars.
LikeLike
I’m not sure if the OverloadedStrings extension is on by default in the latest version of GHC yet, but with the flag set, string literals become polymorphic types. So
(“” :: Text) == []
(“” :: ByteString) == []
would both result in a type error and would not be evaluated. However:
(“” :: String) == []
would work fine since
type String = [Char]
and (“” == []) has the string literal type default to String, so it would work.
LikeLike