type-variables

Unrelated defaults inheritance error for type variables: why?

老子叫甜甜 提交于 2019-11-28 21:16:36
Disclaimer : this is not about this case (while error sounds as same): class inherits unrelated defaults for spliterator() from types java.util.Set and java.util.List and here is why: consider two interfaces (in package " a ") interface I1 { default void x() {} } interface I2 { default void x() {} } It is definitely clear to me why we can not declare such class as: abstract class Bad12 implements I1, I2 { } (!) But I can not understand this restriction with reference to type variables : class A<T extends I1&I2> { List<T> makeList() { return new ArrayList<>(); } } with error: class java.lang

What are skolems?

寵の児 提交于 2019-11-28 17:22:17
Eeek! GHCi found Skolems in my code! ... Couldn't match type `k0' with `b' because type variable `b' would escape its scope This (rigid, skolem) type variable is bound by the type signature for groupBy :: Ord b => (a -> b) -> Set a -> Set (b, [a]) The following variables have types that mention k0 ... What are they? What do they want with my program? And why are they trying to escape (the ungrateful little blighters)? To start with, a "rigid" type variable in a context means a type variable bound by a quantifier outside that context, which thus can't be unified with other type variables. This

How does GHCi pick names for type variables?

纵饮孤独 提交于 2019-11-27 23:38:38
问题 When using the interactive GHC interpreter, it's possible to ask for the inferred type of an expression: Prelude> :t map map :: (a -> b) -> [a] -> [b] It seems that it takes the names of the type variables from the signature since map is defined as map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs in the Prelude. That makes a lot of sense! My question is: how are type variable names picked when there is no signature given? An example would be Prelude> :t map fst map

Haskell: example of function of type a -> a, besides the identity

Deadly 提交于 2019-11-27 13:41:55
问题 I've just started playing a little with Haskell... I want to write a function of the same type of the identity. Obviously, not equivalent to it. That would be something like, myfunction :: a -> a I cannot come up with an example in which the parameter and the return type are the same and can be virtually anything (this excludes the possibility of using Haskell's Typeclasses). 回答1: This is impossible without using undefined as another commenter mentioned. Let's prove it by counter-example.

Unrelated defaults inheritance error for type variables: why?

試著忘記壹切 提交于 2019-11-27 13:38:43
问题 Disclaimer : this is not about this case (while error sounds as same): class inherits unrelated defaults for spliterator() from types java.util.Set and java.util.List and here is why: consider two interfaces (in package " a ") interface I1 { default void x() {} } interface I2 { default void x() {} } It is definitely clear to me why we can not declare such class as: abstract class Bad12 implements I1, I2 { } (!) But I can not understand this restriction with reference to type variables : class

What are skolems?

a 夏天 提交于 2019-11-27 10:13:36
问题 Eeek! GHCi found Skolems in my code! ... Couldn't match type `k0' with `b' because type variable `b' would escape its scope This (rigid, skolem) type variable is bound by the type signature for groupBy :: Ord b => (a -> b) -> Set a -> Set (b, [a]) The following variables have types that mention k0 ... What are they? What do they want with my program? And why are they trying to escape (the ungrateful little blighters)? 回答1: To start with, a "rigid" type variable in a context means a type