4 ms·
You constructed a list! Well done, that was tricky syntax. You used the (:) function. It takes two values, some value and a list, and constructs a new list out
by hartator 14y ago
You constructed a list!
Well done, that was tricky syntax. You used the (:) function. It takes two values, some value and a list, and constructs a new list out of them. We call it 'cons' for short.
No it's not:
> 'a' : []
=> "a"
- kryptiskt 14y agoWhat's the problem? A string in Haskell is a list of chars[1]. So you can construct a string by consing chars to an empty list. Or is there something else you object to? [1] Which incidentally is a reason to avoid using it for anything serious. Text is the better representation of text, and ByteString is better for everything else.
- tkahn6 14y agoWould you accept: > 'a' : "" => "a" Because that's what you did.
- sold 14y agoIn Haskell "a" is the same as ['a']
- niggler 14y agoAs is usually the case with interactive tutorials, unexpected behavior shows up before the clarifying example. Later they show the equivalence of strings "a" and list of chars ['a']