deriving Questions
1
Using:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DeriveDataTypeable #-}
And given the following datatype:
data Event a where
PureE :: a -> Event a
MapE ...
1
Solved
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 alia...
Brassbound asked 6/9, 2022 at 16:27
1
I'm trying to deriving Show, Eq, Ord etc in Idris, but none of the following trials works:
trail #1:
data Expr =
Lit Int
| Neg Expr
| Add Expr Expr
deriving (Show)
got:
deriving.idr:5:15-1...
3
Solved
Let us say we have
data D = X Int | Y Int Int | Z String
I wish to have a function getDConst
getDConst :: D -> String
that returns either "X", "Y", or "Z", according to the data constructo...
Roam asked 18/8, 2013 at 8:39
1
Suppose we have some class Foo such that an instance of Foo f gives us everything necessary to implement Functor f, Foldable f and Traversable f. To avoid overlapping instances, can witness this re...
Philander asked 10/8, 2021 at 2:14
3
Solved
GHC has several useful language extensions for mechanically deriving various common Haskell typeclasses (-XDeriveFunctor, -XDeriveFoldable, -XDeriveTraversable). It seems that Applicative is anothe...
Jacobin asked 17/9, 2013 at 22:57
3
Solved
For a simple example, say I want a type to represent tic-tac-toe marks:
data Mark = Nought | Cross
Which is the same as Bool
Prelude> :info Bool
data Bool = False | True -- Defined in ‘GHC.Type...
Feint asked 22/2, 2021 at 2:8
0
I'm trying to build a streaming library using the abstractions described in the paper "Faster coroutine pipelines". I've modified the code so that it correctly handles pipeline exiting (i...
Jillion asked 14/2, 2021 at 7:16
1
Solved
From a blog post I read
-- | Newtype for disabling logging
newtype NoLoggingT m a
= NoLoggingT { runNoLoggingT :: m a }
deriving newtype (Functor, Applicative, Monad)
deriving (MonadTrans) via I...
Earplug asked 12/8, 2020 at 6:39
2
I am trying to define an instance:
newtype Join a = Join { getJoin :: a -> Bool }
deriving Generic
instance Monoid (Join a) where
f <> g = ???
mempty = ???
The goal is that the functi...
Ghat asked 19/7, 2020 at 16:22
2
Related question - Is it safe to derive MonadThrow, MonadCatch, MonadBaseControl, MonadUnliftIO, etc? - where I had enabled, both - DeriveAnyClass and GeneralizedNewtypeDeriving
to get the code to...
Corr asked 25/7, 2019 at 9:34
2
I am trying to use this blogpost's approach to higher-kinded data without dangling Identity functors for the trival case together with quantified-constraint deriving:
{-# LANGUAGE TypeFamilies #-}...
Postulate asked 6/6, 2019 at 3:38
3
Solved
I'm experimenting with the Foldable typeclass in Haskell, using the following data type as an example:
data Tree a = Empty
| Node (Tree a) a (Tree a)
If I use the DeriveFoldable GHC extension, ...
2
Solved
I have the following code:
sealed trait Animal
case class Cat(name: String) extends Animal
case class Dog(name: String) extends Animal
trait Show[A] {
def show(a: A): String
}
class Processor[A...
1
I'm trying to create my own data type, which will be part of Monad class, but
newtype Container a = Container a deriving Monad
gives me this error:
* Can't make a derived instance of `Monad Co...
2
I have a dozen of newtypes like this:
newtype MyBool = MyBool Bool
newtype MyInt = MyInt Int
I want to reuse existing instances:
instance MArray IOUArray Int IO where ...
instance MArray (STUAr...
1
Solved
I'm refactoring some old code, which is in a polymorphic, but type-class constrained, monad:
class ( MonadIO m
, MonadLogger m
, MonadLoggerIO m
, MonadThrow m
, MonadCatch m
, MonadMask m
,...
Coccus asked 3/7, 2019 at 5:59
3
Solved
My question seems to be closely related to this
one.
My code parses a yaml file, rearanges the objects and writes a new yaml file. It works perfectly well, but there is a particularly ugly part i...
Lauren asked 20/3, 2019 at 19:18
2
Solved
So, in Haskell, it's really easy to do this:
data Foo = Bar | Baz
deriving (Read, Show)
This is great, but I'd like to be able to pass some data as a string from Haskell to the Elm language. Th...
Imeldaimelida asked 30/8, 2013 at 17:1
1
Solved
I'm not really sure what I'm doing wrong here:
data Vector2D u = Vector2D {
_x :: u,
_y :: u
} deriving stock (Show, Eq, Functor, Foldable, Traversable)
{-# INLINE addVector2 #-}
addVector2 ...
Oulman asked 20/11, 2018 at 23:21
2
Solved
In Haskell, you can derive Functor, Foldable and Traversable automatically using deriving. There is no way to derive Applicative, though. Considering there is one obvious way to define an Applicati...
Stenosis asked 22/4, 2015 at 3:35
1
Solved
I'm trying to use DerivingVia to cut the boilerplate on instance definitions for a multi parameter type class with functional dependencies.
I have these types and class:
{-# LANGUAGE FunctionalDe...
Hombre asked 26/10, 2018 at 13:13
1
Solved
I want to have an annotated AST, so I defined those recursive data structures
using Fix:
data Term a
= Abstraction Name a
| Application a a
| Variable Name
deriving (Read,Show,Eq,Functor,Fold...
Dekko asked 8/9, 2017 at 13:20
1
Solved
I would like to use derived instance like this:
data Test3D = forall a. (Show a, Eq a, Typeable a, Generic a)
=> Test3D { testDt :: String
, testPrm :: a
}
deriving (Show, Eq, Typeable, Gen...
1
Solved
Is there a way to write the following:
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveAnyClass #-}
data X = A | B | C
deriving (Eq, Ord, Show, Read, Data, SymWord, HasKind, SMTValue)
...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.