sanctuary-js / sanctuary-def

Run-time type system for JavaScript
MIT License
294 stars 23 forks source link

question about README #306

Closed spacechimplives closed 2 years ago

spacechimplives commented 2 years ago

In the readme it says:

image

I understand what this means in practice... I need to use MyTypeWithParam ($.Unknown) to generate a new type rather than MyTypeWithParam :: Type -> Type ... but it says that the latter is the "wrong type" ... so I'm wondering why that is? and if there are any resources you all can point me to to understand that a little deeper.

davidchambers commented 2 years ago

Hello, @spacechimplives, and welcome to the community. :wave:

What is the type of the following expression?

[1, 2, 3, Math.sqrt]

We have Array ???, but what is ???? The array's elements are 1 :: Number, 2 :: Number, 3 :: Number, and Math.sqrt :: Number -> Number.

We could apply Math.sqrt to a Number to make a well-typed expression of type Array Number:

[1, 2, 3, Math.sqrt (16)]

What is the type of the following expression?

[$.Boolean, $.Number, $.String, MyTypeWithParam]

We have Array ???, but what is ???? The array's elements are $.Boolean :: Type, $.Number :: Type, $.String :: Type, and MyTypeWithParam :: Type -> Type.

We could apply MyTypeWithParam to a Type to make a well-typed expression of type Array Type:

[$.Boolean, $.Number, $.String, MyTypeWithParam ($.Unknown)]

Does this help to explain the difference between Type and Type -> Type?

spacechimplives commented 2 years ago

Yes, thank you! Now I realize that I missed the part where only objects of type Type are allowed in the environment list. Makes perfect sense.

davidchambers commented 2 years ago

I'm pleased that this now makes sense. :)