3 ms·
> "while exploring the confluence of scripting and functional programming" Scripting and functional go amazing together, as long as it's (mostly) dynamic typin
by sdegutis 10y ago
> "while exploring the confluence of scripting and functional programming"
Scripting and functional go amazing together, as long as it's (mostly) dynamic typing. In general, types really just get in the way when scripting or prototyping or trying to do anything fast, especially when you don't know the types of data you're going to be working with ahead of time, e.g. when it comes from a file or from an external API, etc.
But what is BinTree in the following example on the website? Is it a type? Is it a function, or constructor, or what? I'm confused.
data BinTree:
| leaf
| node(value, left, right)
end
- dexwiz 10y agoPretty sure its a union type.
- AstralStorm 10y agoTagged union type, so no casting.
- xearl 10y ago> "In general, types really just get in the way when scripting or prototyping or trying to do anything fast" I've found the opposite of that claim to be true. Types are absurdly helpful in prototyping or trying to do anything fast, especially when exploring data coming from a file or an external API. Anecdotes aside, BinTree in the example is both a data type and a type testing function ("detector") of signature `Any -> Bool`. See http://www.pyret.org/docs/latest/Declarations.html#%28part._s~3adata-decl%29 http://www.pyret.org/docs/latest/Declarations.html#%28part._... for details.
- AstralStorm 10y agoTypes are great unless you are forced to be explicit instead of the compiler doing automated type deduction.
- Jtsummers 10y agoMy intuition from other languages is that it's a type and a set of constructors. leaf constructs an instance of type BinTree, as does node(4, leaf, leaf). This also matches how it's used in the where clause. The documentation seems to verify my intuition: http://www.pyret.org/docs/latest/A_Tour_of_Pyret.html#%28part._.Data%29 http://www.pyret.org/docs/latest/A_Tour_of_Pyret.html#%28par...
- skrishnamurthi 10y ago`BinTree` is a type. There are two kinds of BinTrees. There are `leaf` BinTrees and there are `node` BinTrees. A leaf has no fields. A node has three fields. Thus, here are some BinTrees: leaf node(1, leaf, leaf) node(2, leaf, node(1, leaf, leaf)) and so on.