derived-instances

How can I get GHC to generate instances of Data.Typeable for GADTs with Typeable in the context?

大兔子大兔子 提交于 2019-12-10 04:17:23
问题 Suppose I have the following code: {-# LANGUAGE GADTs, DeriveDataTypeable, StandaloneDeriving #-} import Data.Typeable class Eq t => OnlyEq t class (Eq t, Typeable t) => BothEqAndTypeable t data Wrapper a where Wrap :: BothEqAndTypeable a => a -> Wrapper a deriving instance Eq (Wrapper a) deriving instance Typeable1 Wrapper Then, the following instance declaration works, without a constraint on t : instance OnlyEq (Wrapper t) and does what I expect it to do. But the following instance

inherit methods declared in .m file

扶醉桌前 提交于 2019-12-08 07:48:46
问题 I now know there is no protected method in objective-c and here is my problem: I have two viewControllers with many functions and properties that are shared, my vision was to have a BaseViewColntroller holding the share methods and properties and from it two classes will inherit and override the needed functionality while using the same variables, I don't wish to convert the shared functions to public by placing them in the .h file to help clarify my question i'm adding code :) @interface

How can I get GHC to generate instances of Data.Typeable for GADTs with Typeable in the context?

穿精又带淫゛_ 提交于 2019-12-05 05:12:48
Suppose I have the following code: {-# LANGUAGE GADTs, DeriveDataTypeable, StandaloneDeriving #-} import Data.Typeable class Eq t => OnlyEq t class (Eq t, Typeable t) => BothEqAndTypeable t data Wrapper a where Wrap :: BothEqAndTypeable a => a -> Wrapper a deriving instance Eq (Wrapper a) deriving instance Typeable1 Wrapper Then, the following instance declaration works, without a constraint on t : instance OnlyEq (Wrapper t) and does what I expect it to do. But the following instance declaration doesn't work: instance BothEqAndTypeable (Wrapper t) since GHC - I'm using 7.6.1 - complains that:

How does deriving work in Haskell?

℡╲_俬逩灬. 提交于 2019-11-27 00:04:05
Algebraic Data Types (ADTs) in Haskell can automatically become instances of some typeclasse s (like Show , Eq ) by deriving from them. data Maybe a = Nothing | Just a deriving (Eq, Ord) My question is, how does this deriving work, i.e. how does Haskell know how to implement the functions of the derived typeclass for the deriving ADT? Also, why is deriving restricted to certain typeclasses only? Why can't I write my own typeclass which can be derived? sclv The short answer is, magic :-). This is to say that automatic deriving is baked into the Haskell spec, and every compiler can choose to

How does deriving work in Haskell?

落爺英雄遲暮 提交于 2019-11-26 09:16:57
问题 Algebraic Data Types (ADTs) in Haskell can automatically become instances of some typeclasse s (like Show , Eq ) by deriving from them. data Maybe a = Nothing | Just a deriving (Eq, Ord) My question is, how does this deriving work, i.e. how does Haskell know how to implement the functions of the derived typeclass for the deriving ADT? Also, why is deriving restricted to certain typeclasses only? Why can\'t I write my own typeclass which can be derived? 回答1: The short answer is, magic :-).