Replies: 2 comments 5 replies
-
Hi Shubhamkar, thanks for your interest!
I really don't know what you are getting at. If you're asking for a Perhaps you mean that traditional unification will make sure that the types of both elements in the pair will be forced to be exactly the same. I'm not sure how that's particularly useful, though.
Sorry, I am not following. Do you have an example?
I didn't see a problem, but I can tell you that typing a dynamic language without the ability to leverage subtyping will likely be much harder. |
Beta Was this translation helpful? Give feedback.
-
Okay, let me try to use a better syntax; apologies for the confusion! In ghci Prelude> data Pair a = MakePair a a deriving Show
Prelude> MakePair 2 3
MakePair 2 3
Prelude> MakePair 2 "a"
<interactive>:11:10: error:
• No instance for (Num [Char]) arising from the literal ‘2’
• In the first argument of ‘MakePair’, namely ‘2’
In the expression: MakePair 2 "a"
In an equation for ‘it’: it = MakePair 2 "a"
Prelude> MakePair "a" "b"
MakePair "a" "b"
Prelude> MakePair 'a' 'c'
MakePair 'a' 'c'
Prelude> MakePair 'a' "c"
<interactive>:15:14: error:
• Couldn't match expected type ‘Char’ with actual type ‘[Char]’
• In the second argument of ‘MakePair’, namely ‘"c"’
In the expression: MakePair 'a' "c"
In an equation for ‘it’: it = MakePair 'a' "c" So, above, However, in a system that allows the "top" type, because all the values are of type "top", all pairs of arguments to I certainly do agree with you that the types |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Thank you for the paper! I was wondering if you (or anyone passing by this thread) have any thoughts about what implication subtyping (particularly the existence of the "top" type) has for polymorphic data types. Sorry if this is something that can be derived from the work in the paper.
My understanding is that, in standard ML / Haskell or equivalent, it is possible to write
Pair<T>
to denote a pair of elements of identical type<T>
. However, I don't see how this type is any useful in the presence of the "top" type, because ifT
is thetop
type, then this would makePair<T>
as a pair of any arbitrary elements. On the other hand, whenT
isint
ornat
, then it results in a somewhat useful type as is the case with ML/Haskell.I am also coming from a Common Lisp background, and here it is also possible to express types corresponding to singleton elements. For instance, the type
(eql 5)
corresponds to the value 5, and nothing else! And in the above discussion aboutPair<T>
type, such singleton types can lead to some fairly useless types.Common Lisp type system is indeed dirty, and I have been wondering about a better typing layer over it. But while Common Lisp makes heavy use of subtyping (in some sense of the term), I'm wondering if I should give up on subtyping due to the above problem, or if there are saner ways to deal with it. So, I'd be happy to know if you have any thoughts on how a data type like
Pair<T>
of standard ML could be expressed in the presence of subtyping.Beta Was this translation helpful? Give feedback.
All reactions