Live data from Hacker News

Type Systems Explained with Examples

thevaluable.dev

21–30 of 34 posts

Re: Type Systems Explained with Examples

#21
post #4

I would pay good money for a comparison of type systems, delivered in the vein of Cow Economics. In Self, you have a cow. You ask the cow to moo. It moos. In Java, you have a cow. You construct a CowMooFactory to create an MooIpml. The MooImpl moos. In Python, you have a cow. You ask it to moo. It quacks. In C, you have a pointer to a cow. You ask it to moo. Segmentation fault (core dumped).

Didn't think Python had duck typing...

Re: Type Systems Explained with Examples

#22
post #4

I would pay good money for a comparison of type systems, delivered in the vein of Cow Economics. In Self, you have a cow. You ask the cow to moo. It moos. In Java, you have a cow. You construct a CowMooFactory to create an MooIpml. The MooImpl moos. In Python, you have a cow. You ask it to moo. It quacks. In C, you have a pointer to a cow. You ask it to moo. Segmentation fault (core dumped).

In Haskell mooing is an impure side effect. It has to be handled with a special design pattern - which recursively generates further side effects, including an infinite number of online tutorials which fail to explain what it does.

This pattern is called a Moonad.

Re: Type Systems Explained with Examples

#23
post #12

I suspect the use of “semantic” where it should be “semantics” is explained by the French author translating “semantique” a little too directly.

Why does English has all those random "s" at the end of the Greek-borrowed words? AFAIK, most other languages that borrowed the same words don't have those.

Found an interesting paper on this!

https://www.tandfonline.com/doi/pdf/10.1080/00437956.2007.11...

"The morphology of English words like dependence, linguistics, and news suggests that English has an /-s/ suffix forming certain kinds of abstract nouns not used as plurals. While dependence and dependents are homophones, the former takes singular verb agreement, as do linguistics and news, and the latter takes plural. We argue that English has a highly productive derivational suffix /-s/ that creates abstract nouns from adjectives, dependence from dependent + /-s/, linguistics from linguistic + /-s/, and news from new + /-s/. While this suffix originated in the Latin present participle, the sources of a modern /-s/ came into English through extensive borrowing from Latin and French as well as through loan translation and borrowing of Greek words, but then it combined with existing English /-s/ that marked plural or genitive. Orthographic, phonological, morphological, and semantic evidence suggests that this modern /-s/ arose from several distinct sources that came together as a single suffix in the early 171h century."

Re: Type Systems Explained with Examples

#24
post #21
post #4

I would pay good money for a comparison of type systems, delivered in the vein of Cow Economics. In Self, you have a cow. You ask the cow to moo. It moos. In Java, you have a cow. You construct a CowMooFactory to create an MooIpml. The MooImpl moos. In Python, you have a cow. You ask it to moo. It quacks. In C, you have a pointer to a cow. You ask it to moo. Segmentation fault (core dumped).

Didn't think Python had duck typing...

What do you think "duck typing" is? Historically, it feels like I've mostly heard the term applied to Python.

Edited to add: Please don't take my question as rhetorical attack - it was intended as inquiry. There may be different definitions floating around.

Re: Type Systems Explained with Examples

#25
post #4

I would pay good money for a comparison of type systems, delivered in the vein of Cow Economics. In Self, you have a cow. You ask the cow to moo. It moos. In Java, you have a cow. You construct a CowMooFactory to create an MooIpml. The MooImpl moos. In Python, you have a cow. You ask it to moo. It quacks. In C, you have a pointer to a cow. You ask it to moo. Segmentation fault (core dumped).

In Haskell mooing is an impure side effect. It has to be handled with a special design pattern - which recursively generates further side effects, including an infinite number of online tutorials which fail to explain what it does. This pattern is called a Moonad.

You mean https://github.com/moonad/Moonad ?

Re: Type Systems Explained with Examples

#28
post #23

Earlier quoted context omitted.

Why does English has all those random "s" at the end of the Greek-borrowed words? AFAIK, most other languages that borrowed the same words don't have those.

Found an interesting paper on this! https://www.tandfonline.com/doi/pdf/10.1080/00437956.2007.11... "The morphology of English words like dependence, linguistics, and news suggests that English has an /-s/ suffix forming certain kinds of abstract nouns not used as plurals. While dependence and dependents are homophones, the former takes singular verb agreement, as do linguistics and news, and the latter takes plural.…

That's interesting... German has still the genitive case and it is formed with an "s" too. That's a nice resource, thanks for that!

Re: Type Systems Explained with Examples

#29
post #7
post #2

If anyone is interested in Type systems and what's a type, I highly recommend watching the first 20 mins of Sean Parent's presentation: https://youtu.be/sWgDk-o-6ZE It will change the way you think about types after this.

That video is titled CppCon 2015: Sean Parent "Better Code: Data Structures" Did you mean instead this video? https://www.youtube.com/watch?v=mYrbivnruYw Goals for Better Code - Implement Complete Types

Having watched both, I believe the parent comment meant the talk they linked. The first 20 minutes has some talk about representation and type and meaning.

Both talks are interesting. Both are from a very C++ perspective, particularly the one you suggest. That doesn't make them wrong, by any means. Much of it generalizes, although depending on your background it might take varying amounts of effort to understand the generalizations.

In the first talk in particular, I think he conflates (in a small way) type with representation in a way that's... not... ideal? But I don't think it does a lot of harm to the talk; he has very interesting things to say particularly about representation.

Some of the point of both talks overlaps with the common admonishment to "make illegal states unrepresentable", but I don't think any fully implies the other.

For a very different perspective on types, I highly recommend watching https://www.youtube.com/watch?v=3U3lV5VPmOU, although I don't highly recommend actually programming this way.

Re: Type Systems Explained with Examples

#30
post #6

Earlier quoted context omitted.

In ML, your value moos. It is inferred to be a cow. In Ruby, your value moos. Could be a cow; might be a MooDuck. Do you really care?

So what's the difference between ruby and python?

About 3 seconds, depending on how many cows you have. ;)
Post reply on HN