Skip to main content

Questions tagged [deriving]

In Haskell, a derived instance is an instance declaration that is generated automatically in conjunction with a data or newtype declaration. The body of a derived instance declaration is derived syntactically from the definition of the associated type.

0 votes
0 answers
60 views

Deriving FromRow on a type with [String] field

I am building a haskell server with a postgres database. I am using postgresql-simple to query the db. I have the following type: data Reading = Reading { id :: UUID , title :: String , authors ...
Razumov's user avatar
  • 302
2 votes
1 answer
57 views

Deriving `Eq` for a data type based on a type family in Haskell

I'm working with type-level programming in Haskell and have encountered an issue with deriving an Eq instance for a data type based on a type family. Here's a simplified version of my code: {-# ...
jan.vogt's user avatar
  • 1,817
0 votes
1 answer
53 views

Deriving newtype recursively like functionality

Lets say, in package P, I've got a type A, defined something like so: newtype A = A Int There's then external package X (which I don't control, unlike P and Q), which has a class C and an instance: ...
Clinton's user avatar
  • 22.9k
2 votes
0 answers
197 views

Which kinds of lawfull `Functor`s are possible in Haskell?

I know following types of Functors: Polynomial functor == simple not-nested parameterized datatype Generalization of 1, by using "parameter removing" newtypes: Fix, Some (existentials), ...
uhbif19's user avatar
  • 3,225
1 vote
1 answer
103 views

Trying to add deriving(Show, Read) to an expression tree

I am fairly new to Haskell so it is probably something simple that I am missing but I have an expression tree that looks like this: data Expression = Lit Float | Add Expression ...
skiboy108's user avatar
7 votes
1 answer
741 views

Derive typeclass instances for opaque types in Scala 3

Is there a way in Scala 3 to use derives keyword in combination with opaque type aliases? It would be nice to have a boilerplate-free way to provide a typeclass instance to a given opaque type alias ...
alessandro candolini's user avatar
0 votes
1 answer
412 views

How to use deriving Show() in mutually recursive types?

Let's directly see the codes. type symbol = | JumpDes of int | CallDes of func | StarDes of exp (*here needs the definition of type exp*) deriving (Show) type exp = | Const of const |...
S1mple's user avatar
  • 45
3 votes
0 answers
132 views

Why automatical deriving for newtype does not work

I use library msgpack-types-0.0.4 and I have a type: newtype A = A Text and I tried deriving MessagePack, deriving newtype MessagePack, standalone derivings, it seems nothing works (or I do something ...
RandomB's user avatar
  • 3,645
3 votes
2 answers
244 views

Problem when deriving Eq from data type with function as field in Haskell

I'm trying to deriving Eq from data type with a function as a field but doesn't work as expected. I also try to write te instance but still doesn't work data Conf = Conf { rule :: ([Char] -> ...
Javier Sánchez Castro's user avatar
4 votes
2 answers
252 views

Can I use DerivingVia to derive instances for data types isomorphic to tuples

Given the following data type data Both a b = Both { left :: a, right :: b } I can write instances for Applicative etc. like so (omitting Functor here as we can use DeriveFunctor): instance Monoid a =...
l7r7's user avatar
  • 1,256
4 votes
3 answers
183 views

Alternative of Show that only uses name

Is there something like Show (deriving Show) that only uses an algebraic datatype's constructors? (please don't mind that I'm using the word constructor, I don't know the right name...) The reason for ...
John Smith's user avatar
  • 2,322
3 votes
1 answer
185 views

Deriving via ReaderT

I'm writing the Monad instance for this type using ReaderT and deriving via newtype HIO a = HIO {runHIO :: Set HiPermission -> IO a} I've tried to do it this way newtype HIO a = HIO {runHIO :: Set ...
Maria Z's user avatar
  • 31
0 votes
1 answer
236 views

Using "deriving via" with a type family

I have a typeclass with a default implementation, and would like to provide a simple way to derive the typeclass if a user wants to use their custom monad. Here's a solution someone else provided me: {...
Edward's user avatar
  • 89
2 votes
0 answers
42 views

Deriving from std::vector - what am I doing wrong? [duplicate]

Trying to switch from some custom made classes I built to std classes. Just for a start, I am trying to derive from std::vector. #include <vector> template < class DATA_T > class CArray : ...
Razzupaltuff's user avatar
  • 2,270
1 vote
1 answer
207 views

Deriving a class instance for a type based on another class it's an instance of

I have a situation where I have some similar newtypes that all need to be instances of Random, Arbitrary, and lots of other stuff. They all need the same custom implementation of the functions randomR,...
mhwombat's user avatar
  • 8,086

15 30 50 per page
1
2 3 4 5
10