I have a class Cyc cr which has functions for datas of the form cmr , where m is a phantom type. For example, class Cyc c r where cyc :: (Foo m, Foo m') => c m r -> c m' r I do have good reasons for not making m a class parameter. For the purposes of this example, the primary reason is that it reduces the number of constraints on functions. In my actual example, a more compelling nee
我有一个类Cyc cr ,它具有形式为cmr数据的功能,其中m是幻像类型。 例如, class Cyc c r where cyc :: (Foo m, Foo m') => c m r -> c m' r 我确实有很好的理由不让m类参数。 就本例而言,主要原因是它减少了函数约束的数量。 在我的实际例子中,这个接口更引人注目的需求是我使用变化和隐藏的幻像类型,所以这个接口让我得到任何幻像类型的Cyc约束。 这种选择的一个缺点是我不能让Num (cmr)成为Cyc的超类约束
I've got a function foo with a litany of constraints. Of course these constraints must appear in the signatures of functions that use foo , so what I'm trying to do is wrap the foo constraints in a type synonym FooCtx ab ... :: Constraint . As an example, foo :: (A a, B b, C c, ...) => a -> b -> c bar :: (A a, B b, C c, ...) ... bar = ... foo ... would become type FooCtx a
我有一个功能foo与一系列的约束。 当然,这些约束必须出现在使用foo的函数的签名中,所以我想要做的就是将foo约束包装在类型同义词FooCtx ab ... :: Constraint 。 举个例子, foo :: (A a, B b, C c, ...) => a -> b -> c bar :: (A a, B b, C c, ...) ... bar = ... foo ... 会成为 type FooCtx a b c ... = (A a, B b, C c, ...) foo :: (FooCtx a b c) => a -> b -> c bar :: (FooCtx a b c) => .
I am getting type inference errors because GHC will not infer a constraint variable. It looks inferable by first-order unification. In further investigation, I found that inserting let-bindings changes the behavior of type inference. I'd like to know what GHC is doing. The code here demonstrates the problem. The newtype ConstrainedF c stands for a polymorphic function whose type paramet
我得到类型推断错误,因为GHC不会推断出一个约束变量。 它看起来可以通过一阶统一来推断。 在进一步的调查中,我发现插入let-bindings会改变类型推断的行为。 我想知道GHC在做什么。 这里的代码演示了这个问题。 新类型ConstrainedF c表示一个多态函数,其类型参数受c约束。 据我所知,GHC不会根据给予ConstrainedF的值来推断c 。 {-# LANGUAGE RankNTypes, ScopedTypeVariables, ConstraintKinds, MonoLocalBinds #-} i
When I try to pattern-match a GADT in an proc syntax (with Netwire and Vinyl): sceneRoot = proc inputs -> do let (Identity camera :& Identity children) = inputs returnA -< (<*>) (map (rGet draw) children) . pure I get the (rather odd) compiler error, from ghc-7.6.3 My brain just exploded I can't handle pattern bindings for existential or GADT dat
当我尝试使用proc语法(使用Netwire和Vinyl)对GADT进行模式匹配时: sceneRoot = proc inputs -> do let (Identity camera :& Identity children) = inputs returnA -< (<*>) (map (rGet draw) children) . pure 我得到(很奇怪)编译器错误,从ghc-7.6.3 My brain just exploded I can't handle pattern bindings for existential or GADT data constructors. Instead,
GHC has a whole zoo of type system extensions: multiparameter type classes, functional dependencies, rank-n polymorphism, existential types, GADTs, type families, scoped type variables, etc., etc. Which ones are likely to be easiest to learn about first? Also, do these features fit together in some way, or are they all pretty much separate ideas useful for entirely different purposes? A good o
GHC有一个类型系统扩展的整个动物园:多参数类型类,函数依赖关系,等级n多态性,存在类型,GADT,类型族,范围类型变量等等,哪些可能最容易学习? 另外,这些功能是否以某种方式组合在一起,还是它们都是完全不同的用途,而且都是独立的想法? 一个很好的学习是ScopedTypeVariables ,因为它们对调试函数中的类型问题非常有用。 当我有一个令人困惑的类型错误时,我临时为函数中的每个表达式添加类型声明。 (通常你需要
My question is about how to put an equality constraint in an associated type constraint (ie type of kind Constraint) The specific use case is a class parameterized by a partially applied type: class Foo c where -- c has kind *->*->* type Ctx c m r :: Constraint f :: (Ctx c m r) => c m r -> c m r In a particular instance, I would like to write: data Bar m r = ... instance Foo
我的问题是关于如何在关联类型约束中放置一个等式约束(即种类约束) 具体用例是一个由部分应用类型参数化的类: class Foo c where -- c has kind *->*->* type Ctx c m r :: Constraint f :: (Ctx c m r) => c m r -> c m r 在特定的情况下,我想写: data Bar m r = ... instance Foo Bar where type Ctx Bar m r = (m~Maybe b) -- m must be a Maybe, I don't care what its parameter is f
I wanted to write a library that can convert types between various isomorphic formats and from "subtypes" to "supertypes", for example using the following isomorphisms and injections: (a, (b, c)) <~> ((a, b), c) (Either a (Either bc)) <~> (Either (Either ab) c) (a, ()) <~> a <~> ((), a) (Either a Void) <~> a <~> (Either Void a) (a,
我想写一个库,可以在各种同构格式之间转换类型,并从“子类型”转换为“超类型”,例如使用以下同构和注入: (a, (b, c)) - ((a, b), c) (Either a (Either bc)) (Either (Either ab) c) (a, ()) a ((), a) (Either a Void) a (Either Void a) (a, Void) Void (Void, a) ((a, b) -> c) → a -> (b -> c) (() -> c) c (a, Either xy) Either (a, x) (a, y) (Either xy, a) Either (x, a) (y, a) a 〜
Using the GHC RULES pragma, it is possible to specialise a polymorphic function for specific types. Example from the Haskell report: genericLookup :: Ord a => Table a b -> a -> b intLookup :: Table Int b -> Int -> b {-# RULES "genericLookup/Int" genericLookup = intLookup #-} This would make GHC use intLookup on an integer-indexed table and the generic version o
使用GHC RULES编译指示,可以为特定类型专门设计一个多态函数。 来自Haskell报告的例子: genericLookup :: Ord a => Table a b -> a -> b intLookup :: Table Int b -> Int -> b {-# RULES "genericLookup/Int" genericLookup = intLookup #-} 这将使GHC在整数索引表上使用intLookup ,否则在泛型上使用intLookup ,其中intLookup可能更有效。 我想用类似下面的(稍微简化的)函数来完成
I just noticed while trying to learn to read GHC Core, that the automatically derived Eq instance for enum-style data types such as data EType = ETypeA | ETypeB | ETypeC | ETypeD | ETypeE | ETypeF | ETypeG | ETypeH deriving (Eq) seems to be transformed into a O(N)-like lookup when looking at GHC's core representation: $fEqEType_$c== = (a_ahZ :: EType) (b_ai0 :: ETy
我只是在尝试学习阅读GHC Core时注意到,自动派生的枚举类型数据类型的Eq实例如 data EType = ETypeA | ETypeB | ETypeC | ETypeD | ETypeE | ETypeF | ETypeG | ETypeH deriving (Eq) 在查看GHC的核心代表时,似乎转变为O(N)式的查询: $fEqEType_$c== = (a_ahZ :: EType) (b_ai0 :: EType) -> case a_ahZ of _ { ETypeA -> case b_ai0 of _ { ETypeA -> Tr
A type constructor produces a type given a type. For example, the Maybe constructor data Maybe a = Nothing | Just a could be a given a concrete type, like Char, and give a concrete type, like Maybe Char. In terms of kinds, one has GHCI> :k Maybe Maybe :: * -> * My question: Is it possible to define a type constructor that yields a concrete type given a Char, say? Put another way, is
类型构造函数产生给定类型的类型。 例如,Maybe构造函数 data Maybe a = Nothing | Just a 可以是给定的具体类型,如Char,并给出具体类型,如Maybe Char。 就种类而言,有一个 GHCI> :k Maybe Maybe :: * -> * 我的问题:是否有可能定义一个类型构造函数产生一个具体的类型给予一个字符,说? 换句话说,是否可以在类型构造函数的类型签名中混合种类和类型? 就像是 GHCI> :k my_type my_type :: Char -> *