News for hackers. Stuff that matters.
Re:Making Wrong Code Look Wrong by eru on Monday August 22, 2011 @04:23PM (#2913966)
Yes, that's possible in Haskell. And it's actually one of the canonical examples.

And even in C you could wrap your (char*)s up in different structs. The typing overhead would be higher than in Haskell, though.

(There's even a language extension to allow you to overload string literals. But you probably don't want that, because

    s = TaintedString "My string literal"
is easier to read than:

    s :: TaintedString
    s = "My string literal"
The overloading makes more sense for implementation details like using a different String implementation like ByteStrings instead of a linked list of Characters. You actually want to be able to see the semantic differences.)
Re:Making Wrong Code Look Wrong by masklinn on Tuesday August 23, 2011 @05:26AM (#2915956)
Re. second one, wouldn't it also be possible to write

    s = "My string literal" :: TaintedString
?

It's not shorter than the constructed version but it should work, you sometimes need it to get the "right" kind of number out of a literal when the type inference gets confused (or more commonly in the REPL)

Re:Making Wrong Code Look Wrong by eru on Tuesday August 23, 2011 @12:31PM (#2917223)
Yes, that's possible with the right compiler extensions. For this example it's essentially the same thing as giving the type on its own line, so I chose the more common syntax.