list,haskell,compiler-flags,algebraic-data-types,gadt

It looks like you're trying to restrict lists to only be able to hold values that implement Eq, and you can't do that without extensions. You can, however, tell the compiler how to compare two List as when a has a type that implements Eq. There are two easy ways...

haskell,abstract-data-type,algebraic-data-types,gadt

There is no independent concept named generalized abstract data type. The phrase "generalized abstract data type" is sometimes incorrectly used for generalized algebraic data type. This mistake arises because both "algebraic data type" and "abstract data type" are abbreviated as "ADT".

The standard technique is to define an existential type: data ETerm_ where ETerm_ :: TTerm a -> ETerm In this case, you may also want some term-level evidence of which type you have; e.g. data Type a where TInt :: Type Int TBool :: Type Bool then the real ETerm...

You can't do this without GADT, as phantom type cannot serve as a witness for a compiler, that an expression has specific type, since with phantom type you actually can do the following: let bool b : int value = Bool b;; val bool : bool -> int value =...

haskell,typeclass,gadt,constraint-kinds

An open variant of Daniel Wagner's answer would use a TypeFamily to let each type that implements the class specify a context that it needs. {-# LANGUAGE GADTs #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE ScopedTypeVariables #-} import GHC.Exts (Constraint) import Data.Proxy data Dict c where...

The signature prodV :: (Num a) => V a -> V a -> a mandates that both arguments have the same type parameter, but if you match on V0 and Vn the arguments would have to have the types V Float and V [Float] in which the type parameter does...

You need explicit type annotations when GADTs are involved: abigail :: Person abigail = let x :: Person x Name = "Abigail" x Age = 27 in x Without it, GHC roughly sees let x Name = "Abigail" and says "OK, x is a function from the type of Name,...

The closest we are able to get is a Class1 class that reifys the relationship between a class and a single superclass constraint as a class. It's based on the Class from constraints. First, we'll take a short tour of the constraints package. A Dict captures the dictionary for a...

haskell,gadt,type-families,data-kinds,constraint-kinds

I see now that the question is how to write a proof of (All p xs, All p ys) => All p (xs :++: ys). The answer is, by induction, of course! The type of the function we really want to write is allAppend :: (p :: Constraint) -> (xs...

gadt,higher-rank-types,purescript

The syntax used for existential types in Haskell is not present in PureScript. What you've written for Cons is a data constructor with a single universally-quantified argument. You might like to try using purescript-exists to encode the existential type instead. Another option is to use a final-tagless encoding of the...

haskell,typechecking,gadt,unification

This may be related to a feature left/right decomposition of coercions that was temporarily removed from GHC's type inference system in order to support more flexible ("unsaturated") type functions, and then reintroduced when it was found to have annoying effects like this.

haskell,gadt,existential-type,phantom-types

Start with the Toy type: data Toy a where TBool :: Bool -> Toy Bool TInt :: Int -> Toy Int Now you can wrap it up in an existential without over-generalizing with the class system: data WrappedToy where Wrap :: Toy a -> WrappedToy Since the wrapper only holds...

You can use existentials: {-# LANGUAGE GADTs, DataKinds, PolyKinds #-} data Exists :: (k -> *) -> * where This :: p x -> Exists p data JSExp :: Bool -> * where ... JSArray :: [Exists JSExp] -> JSExp False test = let aref = JSReference "a" in JSArray...

haskell,types,refactoring,gadt

3 and 4 seem incompatible. This sounds like a "fallback" mechanism: use this instance if no more specific instance is available. You can get this with OverlappingInstances, but I always seem to run into trouble with it. Worth a shot, I guess. As for the rest of your problem, it...

The problem is you're fixing the final result type, so the instance exists and the type checker can find it. Try something like: run :: GADT e a -> e Now the result type can't pick the instance for review and parametricity enforces your invariant....