type-variables

Fixing type variables in locale extensions

≡放荡痞女 提交于 2021-02-07 20:14:36
问题 Given this code locale A = fixes foo :: "'a" locale B = A + fixes bar :: "'a × 'a" locale C' = A + fixes baz :: "'a" begin sublocale B foo "(foo, baz)". end I get Type unification failed Failed to meet type constraint: Term: (foo, baz) :: 'b × 'a Type: 'b × 'b so it seems that Isabelle does not understand that baz and foo should be of the same type. Is there a way to fix this? 回答1: The problem is with your declaration of locales B and C . The declaration for B is equivalent to the following

Fixing type variables in locale extensions

北战南征 提交于 2021-02-07 20:09:55
问题 Given this code locale A = fixes foo :: "'a" locale B = A + fixes bar :: "'a × 'a" locale C' = A + fixes baz :: "'a" begin sublocale B foo "(foo, baz)". end I get Type unification failed Failed to meet type constraint: Term: (foo, baz) :: 'b × 'a Type: 'b × 'b so it seems that Isabelle does not understand that baz and foo should be of the same type. Is there a way to fix this? 回答1: The problem is with your declaration of locales B and C . The declaration for B is equivalent to the following

How do I generically iterate over the properties of an arbitrary object in TypeScript?

对着背影说爱祢 提交于 2021-01-27 17:10:14
问题 This is a pretty common JavaScript pattern: function mapThruWrapper(module) { const replacement = {} Object.getOwnPropertyNames(module).forEach(function(key) { const val = module[key] if (val instanceof Function) { replacement[key] = wrapperFunc.bind(null, val) } else { replacement[key] = val } }) return replacement } I'm trying to strongly type this in TypeScript, and I've gotten as far as something like the following: function mapThruWrapper<M extends { [X: string]: unknown }>(module: M): M

ScopedTypeVariables fail to work with nested where-clauses?

烂漫一生 提交于 2021-01-27 06:51:29
问题 It's a horribly contrived example, but anyway... this typechecks: newtype Foo c = Foo { runFoo :: c -> Bool } newtype Bar c = Bar { runBar :: Int -> c } foo :: Eq c => Bar c -> (c -> [c]) -> Bar (Foo c) foo bar f = Bar res where res n = Foo judge where judge c = (c`elem`) . f $ runBar bar n and works GHCi> let foo0 = foo (Bar id) (\n -> [n, n*2]) GHCi> map (runFoo $ runBar foo0 4) [1..10] [False,False,False,True,False,False,False,True,False,False] but if I add the obvious type signature to

What's the difference between a constrained TypeVar and a Union?

荒凉一梦 提交于 2020-03-16 05:51:04
问题 If I want to have a type that can represent multiple possible types, Union s seem to be how I represent that: U = Union(int, str) U can be an int or a str . I noticed though that TypeVar s allow for optional var-arg arguments that also seem to do the same thing: T = TypeVar("T", int, str) Both T and U seem to only be allowed to take on the types str and int . What are the differences between these two ways, and when should each be preferred? 回答1: T 's type must be consistent across multiple

What is the rule of the order of multiple type variables in haskell?

[亡魂溺海] 提交于 2020-01-03 07:17:13
问题 For example, ParsecT has multiple type variables in its definition. newtype ParsecT s u m a = ParsecT {unParser :: forall b . State s u -> (a -> State s u -> ParseError -> m b) -> (ParseError -> m b) -> (a -> State s u -> ParseError -> m b) -> (ParseError -> m b) -> m b } Can we do it like this ? newtype ParsecT m a s u -- Only the order of s u m a is changed to m a s u. = ParsecT {unParser :: forall b . State s u -> (a -> State s u -> ParseError -> m b) -> (ParseError -> m b) -> (a -> State

How can I express foldr in terms of foldMap for type-aligned sequences?

空扰寡人 提交于 2020-01-02 01:18:25
问题 I'm playing around with type-aligned sequences, and in particular I'm messing around with the idea of folding them. A foldable type-aligned sequence looks something like this: class FoldableTA fm where foldMapTA :: Category h => (forall b c . a b c -> h b c) -> fm a b d -> h b d foldrTA :: (forall b c d . a c d -> h b c -> h b d) -> h p q -> fm a q r -> h p r foldlTA :: ... It's pretty easy to implement foldrTA in terms of foldMapTA by first using foldMapTA to convert the sequence to a type

Java 'reduceLeft' signature / Lower-bounded Type Arguments

僤鯓⒐⒋嵵緔 提交于 2019-12-10 13:43:30
问题 The following signature is valid and commonly used in Scala: trait Collection[A] { def reduceLeft [B >: A] (f: (B, A) => B): B } However, since >: is the Scala equivalent of super in Java, my first idea to convert this signature (replacing the function type with BiFunction and making use of Use-Site variance annotations aka Bounded Wildcards) would be interface Collection<A> { <B super A> B reduceLeft(BiFunction<? super B, ? super A, ? extends B> mapper) } But oh no ! The compiler complains

Making connections between types and values

你说的曾经没有我的故事 提交于 2019-12-01 09:55:55
问题 I have implementations of type-level arithmetics capable of doing some compile time arithmetic validation, namely <,>,= in two ways: simple implementation rigorous implementation With these, I can have a getFoo function that I can call like this: getFoo[_2,_3] With _2 and _3 being the type-level equivalents of integer values 2 and 3. Now Ideally I would like my getFoo function to take integer values as arguments and attempt to infer _2 from the value 2 . My plan was to add the following

How does GHCi pick names for type variables?

人走茶凉 提交于 2019-11-29 06:09:21
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 fst :: [(b, b1)] -> [b] where it picked names b and b1 . It's clear that renaming must take place, but