type-families

Haskell: Instance definitions for type families

随声附和 提交于 2019-12-20 03:23:30
问题 Lets say we have the following code: class C t where g :: t instance C Int where g = 42 Simple. We can also define functions on Int, like so: f1 :: Int -> Int f1 x = x * x I've been working with type families, in particular because Data.Has uses them, and I want to insert them into an IxSet. But here I'm going to present a simplified example. Lets say we want to define a new type X , that is similar to an Int. We could do this: type family X type instance X = Int We can then define functions

YesodAuthEmail could not deduce m ~ HandlerFor site0 [duplicate]

我的梦境 提交于 2019-12-19 09:49:34
问题 This question already has an answer here : What's wrong with this YesodAuth instance? (1 answer) Closed last year . I'm trying to add instance YesodAuthEmail App to the Yesod-Postgres scaffolding (yesod version 1.6) and getting stuck on a compile error. The relevant code is: instance YesodAuth App where type AuthId App = UserId .... authPlugins :: App -> [AuthPlugin App] authPlugins app = [authOpenId Claimed []] ++ extraAuthPlugins where extraAuthPlugins = [ authEmail ] instance

Type constraints on all type family instances

纵饮孤独 提交于 2019-12-18 15:59:07
问题 I suppose what I want is impossible without Template Haskell but I'll ask anyway. I have an interface for types like Data.Set and Data.IntSet : type family Elem s :: * class SetLike s where insert :: Elem s -> s -> s member :: Elem s -> s -> Bool ... type instance Elem (Set a) = a instance Ord a => SetLike (Set a) where ... And I have a type family which chooses optimal set implementation: type family EfficientSet elem :: * type instance EfficientSet Int = IntSet type instance EfficientSet

ambiguous type error when using type families, and STV is not helping

拈花ヽ惹草 提交于 2019-12-13 02:25:49
问题 {-# LANGUAGE Haskell2010 #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} class PoC m where type Wrapper m :: * -> * wrap :: l -> Wrapper m l I'm working with haskell-src-exts, and I want to upgrade my AST to have freshly generatable labels. Since I want to do it in an extensible fashion, I created an interface like the code above. However, code to upgrade the AST doesn't work. I have the following: upgrade :: forall f m l. (PoC m, Functor f) => f l -> f (Wrapper m l)

Lenses and TypeFamilies

孤者浪人 提交于 2019-12-12 15:07:20
问题 I've encountered a problem of using Control.Lens together with datatypes while using the -XTypeFamilies GHC pragma. {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} import Control.Lens (makeLenses) class SomeClass t where data SomeData t :: * -> * data MyData = MyData Int instance SomeClass MyData where data SomeData MyData a = SomeData {_a :: a, _b :: a} makeLenses ''SomeData The error message is: reifyDatatype: Use a value constructor to reify a data family instance . Is there

How to get around the Coverage Condition for Functional Dependencies without using -XUndecidableInstances

社会主义新天地 提交于 2019-12-12 10:56:25
问题 Wen using functional dependencies, I frequently hit the Coverage Condition . It is possible to lift it with UndecidableInstances , but I usually try to stay away from that extension. Here is a somewhat contrived example, that works without UndecidableInstances : {-# Language MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-} data Result = Result String deriving (Eq, Show) data Arguments a b = Arguments a b class Applyable a b | a -> b where apply :: a -> b -> Result instance

Declare a type to for all higher order kind

好久不见. 提交于 2019-12-11 07:33:48
问题 I have a feeling I'm asking the impossible, but here it goes. I want to associate type constructors with a fully applied version that number's the parameters at the type level with natural numbers. Here's an example ghci session with its desired use: ghci> :kind! MKNumbered Maybe MKNumbered Maybe :: * = Maybe (Proxy Nat 1) ghci> :kind! MKNumbered Either MKNumbered Either :: * = Either (Proxy Nat 1) (Proxy Nat 2) To cut down on the noise of the above a little bit, essentially I get something

Variadic arguments, using Type Families instead of Multi-param Typeclasses

橙三吉。 提交于 2019-12-11 06:49:34
问题 Here's what I've got, expressed with MultiParamTypeClasses: class ListResultMult r a where lstM :: a -> [a] -> r listM :: ListResultMult r a => a -> r listM a = lstM a [] instance ListResultMult r a => ListResultMult (a -> r) a where lstM a as x = lstM x $ a:as instance ListResultMult [a] a where lstM a as = reverse $ a:as instance Show a => ListResultMult (IO ()) a where lstM a as = print . reverse $ a:as Here's what I tried, using TypeFamilies (TypeSynonymInstances didn't help): class

Error while trying to use type families to dissambiguate overlapping instances with flexible contexts

狂风中的少年 提交于 2019-12-11 06:13:14
问题 I'm trying to define instances for typeclasses using some fairly complex conditions on the type arguments of the type I'm working with, and thought that a useful approach would be to declare a closed type family that chooses between the instances I'm defining. Unfortunately, I can't get that idea to work at all, as GHC complains that the instances are duplicates. Here's a simplified example that gives the same error I'm seeing: {-# LANGUAGE FlexibleInstances, TypeFamilies #-} data MyContainer

Making VectorSpace.Scalar instance of Eq

蓝咒 提交于 2019-12-11 04:47:18
问题 Note: I may not need to add Scalar to Eq, although it should solve the problem if I could figure out how to do just that. So I'm trying to add some functionality to the ForceLayout module. Adding mass to Particles like so: data Particle v = Particle { _pos :: Point v , _vel :: v , _force :: v , _mass :: Scalar v } deriving (Eq, Show) But Scalar is not in Eq or Show! So this wont compile. Mass should be a scalar "compatible" with the other vectors though. How can I reconcile this? I don't