problem about gadt-Collection of common programming errors


  • kaosjester
    haskell typeclass gadt data-kinds
    The following definitons are kind of required to understand what I’m asking:data Param = PA | PB | PCdata R p a whereA :: S a -> R PA (S a)B :: S a -> R PB (S a)data S a wherePrim :: a -> S aHO :: R pa a -> R pb b -> S ((R pa a) -> (R pb b))Pair :: R pa a -> R pb b -> S ((R pa a), (R pb b))data Box r a = Box r a I would like to write a function using these definitions that works as follows:trans :: t -> TransIn t -> TransOut twhereTransIn (R ‘PA (S a)) = a TransIn (R ‘PB (S a)) = a TransIn (R ‘PA (S (r1, r2))) = (TransIn r1, TransIn r2) TransIn (R ‘PA (S (r1, r2))) = (TransIn r1, TransIn

  • phynfo
    haskell ghc typeclass gadt
    I have the following GADTdata Vec n a whereT :: Vec VZero a(:.) :: (VNat n) => a -> (Vec n a) -> (Vec (VSucc n) a)to model fixed length vectors, using the class class VNat ndata VZero instance VNat VZerodata VSucc n instance (VNat n) => VNat (VSucc n)I tried to programm an app

  • masonk
    haskell gadt
    I have this type and these functions:data Tag a whereTag :: (Show a, Eq a, Ord a, Storable a, Binary a) => a -> BL.ByteString -> Tag agetVal :: Tag a -> a getVal (Tag v _) = visBigger :: Tag a -> Tag a -> Bool a `isBigger` b =

  • Alessandro Vermeulen
    haskell dsl gadt
    Can we transform a GADT without a given constraint on its constructors to a GADT that does have the said constraint? I want to do this because I want to get a deep-embedding of Arrows and do some interesting things with the representation that (for now) seem to require Typeable. (One reason)data DSL a b whereId :: DSL a aComp :: DSL b c -> DSL a b -> DSL a c–

  • tibbe
    haskell dsl gadt
    In Type-Safe Observable Sharing in Haskell Andy Gill shows how to recover sharing that existed on the Haskell level, in a DSL. His solution is implemented in the data-reify package. Can this approach be modified to work with GADTs? For example, given this GADT:data Ast

  • Eric
    haskell parameterized ambiguous gadt
    I have a pretty straightforward function that takes a parameterized data type and returns the same type:{-# LANGUAGE ScopedTypeVariables #-}class IntegerAsType a wherevalue :: a -> Integernewtype (Num a, IntegerAsType n) => PolyRing a n = PolyRing [a] deriving (Eq) normalize :: (Num a, IntegerAsType n) => (PolyRing a n) -> (PolyRing a n) normalize r@(PolyRing xs) | (genericLength xs)

  • Petr Pudlák
    haskell functor gadt bottom-type
    When discussing Void on Haskell Libraries mailing list, there was this remark:Back in the day it used to be implemented by an unsafeCoerce at the behestof Conor McBride who didn’t want to pa

  • James Koppel
    haskell types gadt
    Consider the following code:data (:+:) f g a = Inl (f a) | Inr (g a)data A data Bdata Foo l whereFoo :: Foo Adata Bar l whereBar :: Bar Btype Sig = Foo :+: Barfun :: Sig B -> Int fun (Inr Bar) = 1Even though fun is an

  • Petr Pudlák

  • yatima2975
    haskell ghc gadt derived-instances
    Suppose I have the following code:{-# LANGUAGE GADTs, DeriveDataTypeable, StandaloneDeriving #-} import Data.Typeableclass Eq t => OnlyEq t class (Eq t, Typeable t) => BothEqAndTypeable tdata Wrapper a whereWrap :: BothEqAndTypeable a => a -> Wrapper aderiving instance Eq (Wrapper a) deriving instance Typeable1 WrapperThen, the following instance declaration works, w

  • Oren Ben-Kiki
    haskell type-inference gadt
    I am trying to create complex data structures with composable logic. That is, the data structure has a generic format (essentially, a record with some fields whose type can change) and some generic functions. Specific structures have specific implementation of the generic functions.There are two approaches I tried. One is to use the type system (with type classes, type families, functional dependencies etc.). The other is creating my own “vtable” and using GADTs. Both methods fail in a similar way – there seems to be something basic I’m missing here. Or, perhaps, there a better more Haskell-ish way to do this?Here is the failing “typed” code:{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeSynonymInstances #-}module Typed whereimport Control.Monad.State import Data.Lens.Lazy import Data.Lens.Template– Generic Block. data Block state ports = Block { _blockState :: state, _blockPorts :: ports }– For the logic we want to use, we need some state and ports. data LogicState = LogicState { _field :: Bool } data LogicPorts incoming outgoing =LogicPorts { _input :: incoming, _output :: outgoing }makeLenses [ ”Block, ”LogicState, ”LogicPorts ]– We need to describe how to reach the needed state and ports, — and provide a piece of the logic. class LogicBlock block incoming outgoing | block -> incoming, block -> outgoing wherelogicState :: block ~ Block state ports => Lens state LogicStatelogicPorts :: block ~ Block state ports => Lens ports (LogicPorts incoming outgoing)convert :: block ~ Block state ports => incoming -> State block outgoingrunLogic :: State block outgoingrunLogic = dostate

Originally posted 2013-11-09 21:18:13.