5 ms·
Haskell doesn't have any subtyping, so the problem doesn't come up. For languages that implement generics in a way that takes variance into account, you can lo
by vilhelm_s 15y ago
Haskell doesn't have any subtyping, so the problem doesn't come up.
For languages that implement generics in a way that takes variance into account, you can look at e.g. Java (ignore the array class, but look at Vector<E>) or Scala. OCaml also has subtyping (for records and variants) and variance-annotated type variables (http://ocaml.janestreet.com/?q=node/99 http://ocaml.janestreet.com/?q=node/99).
- derleth 15y ago> Haskell doesn't have any subtyping Num looks like something that's been subtyped.
- nandemo 15y agoWell, it may look like but it isn't. Num is a typeclass, not a type. Like yummyfajitas said, typeclasses are similar to interfaces or abstract classes in Java, but they aren't the same. Consider Java's equals(). You can write 'a'.equals(foo) as long as foo is an Object. In contrast, look at Haskell's (==) function declared in Eq (I'm not giving an example using Num because Haskell provides some implicit conversions for numeric literals, which would introduce an unrelated complication in the example). (==) :: (Eq a) => a -> a -> Bool This functions accepts 2 arguments of any one type, as long that type is an instance of Eq. But we cannot use different types in the same call. That is, we can write ('a' == 'b') and ("foo" == "bar") but not ('a' = "foo"), because (==) is not defined for a Char and a String.