3 ms·
Haskell is very powerful, but I don't think this article presents anything that's widely available in popular languages right now. I'd be very skeptical that Ty
by prionassembly 5y ago
Haskell is very powerful, but I don't think this article presents anything that's widely available in popular languages right now. I'd be very skeptical that TypeScript isn't expressive enough to do Maybe and Either; I wouldn't be surprised in PHP is there already.
- jerf 5y agoYour post as I read it is very hard to parse, but I don't think the article claimed that Typescript couldn't do it. Many modern languages can do Either or Maybe types precisely because they copied it from Haskell in the first place. (Which is good. Copying is good.) The dynamic scripting languages can do a "maybe" type because they can do just about anything when it comes to types; what they can't do is enforce correct usage by restrictions, so you write a Maybe type but you can't ever quite be sure it's doing what you think it's doing. This is just something you end up living with in dynamically typed langauges.
- fooyc 5y agoTypescript is a static type system though
- jerf 5y agoYes, the paragraph break was there for a reason.
- prionassembly 5y agoExpressivity and automatic enforcement are completely orthogonal. Some pseudocode in academic papers is sublimely expressive, but can't be typed directly on a computer.
- dllthomas 5y agoTypescript can do Maybe and Either, but it's a little verbose because you have to manage the tags yourself. For instance you can certainly do: type Maybe<X> = { tag: 'just', value: X } | { tag: 'nothing'}; type Either<X, Y> = { tag: 'left', value: X } | { tag: 'right', value: Y }; function either<X, Y, Z>(fromLeft: (x: X) => Z, fromRight: (y: Y) => Z, xy: Either<X, Y>): Z { switch (xy.tag) { case 'left': return fromLeft(xy.value); case 'right': return fromRight(xy.value); } } Note that this is meaningfully different from the (often more idiomatic and certainly less verbose) untagged use of union types because you can distinguish left from right even when the contained types agree and you can distinguish different nestings, for better and for worse.