gadt

Pattern matching in Observational Type Theory

江枫思渺然 提交于 2019-12-03 10:35:00
In the end of the "5. Full OTT" section of Towards Observational Type Theory the authors show how to define coercible-under-constructors indexed data types in OTT. The idea is basically to turn indexed data types into parameterized like this: data IFin : ℕ -> Set where zero : ∀ {n} -> IFin (suc n) suc : ∀ {n} -> IFin n -> IFin (suc n) data PFin (m : ℕ) : Set where zero : ∀ {n} -> suc n ≡ m -> PFin m suc : ∀ {n} -> suc n ≡ m -> PFin n -> PFin m Conor also mentions this technique at the bottom of observational type theory (delivery) : The fix, of course, is to do what the GADT people did, and

Future of roles for GADT-like type variables?

泄露秘密 提交于 2019-12-03 08:42:36
问题 A question from yesterday had a definition of HList (from the HList package) that uses data families. Basically: data family HList (l :: [*]) data instance HList '[] = HNil newtype instance HList (x ': xs) = HCons1 (x, HList xs) pattern HCons x xs = HCons1 (x, xs) instead of the usual (IMO more elegant and intuitive) GADT definition data HList (l :: [*]) where HNil :: HList '[] HCons :: x -> HList xs -> HList (x ': xs) This is because the data family version lets us coerce (we only get to

makeLenses for GADTs (Haskell)

只愿长相守 提交于 2019-12-01 16:41:44
Is there an equivalent of makeLenses for GADTs? If I have a simple GADT like: data D a b where D :: (Ord a, Ord b) => !a -> !b -> D a b Is there a way to generate lenses automatically by passing in a constructor and a list of field names? I don't think it can be done automatically, but writing some lenses by hand isn't that hard in this particular case: {-# LANGUAGE GADTs #-} import Control.Lens data D a b where D :: (Ord a, Ord b) => !a -> !b -> D a b field1 :: Lens' (D a b) a field1 f (D x y) = fmap (\x' -> D x' y) (f x) field2 :: Lens' (D a b) b field2 f (D x y) = fmap (\y' -> D x y') (f y)

List of any `DataKind` in GADT

落花浮王杯 提交于 2019-12-01 11:32:13
问题 Disclaimer GADTs & DataKinds are unexplored territory for me, so some of the limitations and capabilities of them are unknown to me. The Question So I'm writing an AST for a JavaScript code emitter, and I've identified one edge case between expressions and that is that they can either be a reference or not. So I've used GADTS and datakinds to type this aspect of JavaScript expression semantics. The ast looks something like this. Subset of the expression AST -- at the moment I'm just using a

Functions to Polymorphic data types

拟墨画扇 提交于 2019-12-01 06:30:22
data Foo a is defined like: data Foo a where Foo :: (Typeable a, Show a) => a -> Foo a -- perhaps more constructors instance Show a => Show (Foo a) where show (Foo a) = show a with some instances: fiveFoo :: Foo Int fiveFoo = Foo 5 falseFoo :: Foo Bool falseFoo = Foo False How can I define any function from b -> Foo a , for example: getFoo :: (Show a, Typeable a) => String -> Foo a getFoo "five" = fiveFoo getFoo "false" = falseFoo Here getFoo does not type check with Couldn't match type ‘a’ with ‘Bool’ . The only thing that I am interested in here is for a to be of class Show so I can use

Functions to Polymorphic data types

余生长醉 提交于 2019-12-01 05:26:33
问题 data Foo a is defined like: data Foo a where Foo :: (Typeable a, Show a) => a -> Foo a -- perhaps more constructors instance Show a => Show (Foo a) where show (Foo a) = show a with some instances: fiveFoo :: Foo Int fiveFoo = Foo 5 falseFoo :: Foo Bool falseFoo = Foo False How can I define any function from b -> Foo a , for example: getFoo :: (Show a, Typeable a) => String -> Foo a getFoo "five" = fiveFoo getFoo "false" = falseFoo Here getFoo does not type check with Couldn't match type ‘a’

How can holes and contexts be implemented for higher-kinded types in a lens style uniplate library?

末鹿安然 提交于 2019-12-01 04:33:40
András Kovács proposed this question in response to an answer to a previous question. In a lens-style uniplate library for types of kind * -> * based on the class class Uniplate1 f where uniplate1 :: Applicative m => f a -> (forall b. f b -> m (f b)) -> m (f a) analogous to the class for types of kind * class Uniplate on where uniplate :: Applicative m => on -> (on -> m on) -> m on is it possible to implement analogs to contexts and holes , which both have the type Uniplate on => on -> [(on, on -> on)] without requiring Typeable1 ? It's clear that this could be implemented in the old-style of

How can holes and contexts be implemented for higher-kinded types in a lens style uniplate library?

坚强是说给别人听的谎言 提交于 2019-12-01 02:25:16
问题 András Kovács proposed this question in response to an answer to a previous question. In a lens-style uniplate library for types of kind * -> * based on the class class Uniplate1 f where uniplate1 :: Applicative m => f a -> (forall b. f b -> m (f b)) -> m (f a) analogous to the class for types of kind * class Uniplate on where uniplate :: Applicative m => on -> (on -> m on) -> m on is it possible to implement analogs to contexts and holes , which both have the type Uniplate on => on -> [(on,

Parsing and the use of GADTs

♀尐吖头ヾ 提交于 2019-11-30 18:45:34
问题 I've ran into a problem while writing a parser. Specifically, I want to be return values of different types. For example, I have two different data types FA and PA to represent two different lipid classes - data FA = ClassLevelFA IntegerMass | FA CarbonChain deriving (Show, Eq, Ord) data PA = ClassLevelPA IntegerMass | CombinedRadylsPA TwoCombinedRadyls | UnknownSnPA Radyl Radyl | KnownSnPA Radyl Radyl deriving (Show, Eq, Ord) Using attoparsec, I have built parsers to parse lipid shorthand

does this GADT actually have type role representational

北慕城南 提交于 2019-11-30 18:25:11
This data type can have type role HCons' representational representational , which allows using coerce to add or remove newtypes applied to the elements, without needing to traverse the list. data HNil' = HNil' data HCons' a b = HCons' a b However the syntax for those lists is not as nice as those with the following GADT data HList (l::[*]) where HNil :: HList '[] HCons :: e -> HList l -> HList (e ': l) I have a class to convert between these two representations , such that Prime (HList [a,b]) ~ HCons' a (HCons' b HNil') . Does that class make coerceHList :: Coercible (Prime a) (Prime b) =>