Skip to content

Instantly share code, notes, and snippets.

@xgrommx
Last active February 21, 2018 13:05
Show Gist options
  • Save xgrommx/2f7a947258e7d3b9cda6c1aaeeaf17a9 to your computer and use it in GitHub Desktop.
Save xgrommx/2f7a947258e7d3b9cda6c1aaeeaf17a9 to your computer and use it in GitHub Desktop.
FreeNum experiments with recursion-schemes and free-functors
/Users/dstoyano/work/app10/src/FreeNum.hs:17:1: error:
• Could not deduce: Data.Constraint.Class1.Subset
(Data.Constraint.Class1.SuperClasses ExprClass)
(Data.Constraint.Class1.SuperClasses ExprClass)
arising from a use of ‘Data.Constraint.Dict’
from the context: Applicative f
bound by the type signature for:
Data.Functor.Free.dictLifted :: forall (f :: * -> *) a.
Applicative f =>
Data.Constraint.Dict
(ExprClass
(Data.Functor.Free.LiftAFree ExprClass f a))
at /Users/dstoyano/work/app10/src/FreeNum.hs:17:1-27
• In the expression: Data.Constraint.Dict
In an equation for ‘Data.Functor.Free.dictLifted’:
Data.Functor.Free.dictLifted = Data.Constraint.Dict
In the instance declaration for
‘Data.Functor.Free.ForallLifted ExprClass’
|
17 | deriveInstances ''ExprClass
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/dstoyano/work/app10/src/FreeNum.hs:17:1: error:
• Could not deduce (Data.Constraint.Class1.HasSuperClasses
ExprClass)
arising from a use of ‘Data.Constraint.Dict’
from the context: Applicative f
bound by the type signature for:
Data.Functor.Free.dictLifted :: forall (f :: * -> *) a.
Applicative f =>
Data.Constraint.Dict
(ExprClass
(Data.Functor.Free.LiftAFree ExprClass f a))
at /Users/dstoyano/work/app10/src/FreeNum.hs:17:1-27
• In the expression: Data.Constraint.Dict
In an equation for ‘Data.Functor.Free.dictLifted’:
Data.Functor.Free.dictLifted = Data.Constraint.Dict
In the instance declaration for
‘Data.Functor.Free.ForallLifted ExprClass’
|
17 | deriveInstances ''ExprClass
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/dstoyano/work/app10/src/FreeNum.hs:32:24: error:
• Could not deduce: Data.Constraint.Class1.Subset
(Data.Constraint.Class1.SuperClasses ExprClass)
(Data.Constraint.Class1.SuperClasses ExprClass)
arising from a use of ‘constant’
• In the expression: constant x
In a case alternative: ConstantF x -> constant x
In the second argument of ‘($)’, namely
‘\case
AtomF a -> return a
ConstantF x -> constant x
ApplicationF a b -> app a b’
|
32 | ConstantF x -> constant x
| ^^^^^^^^^^
/Users/dstoyano/work/app10/src/FreeNum.hs:32:24: error:
• No instance for (Data.Constraint.Class1.HasSuperClasses
ExprClass)
arising from a use of ‘constant’
• In the expression: constant x
In a case alternative: ConstantF x -> constant x
In the second argument of ‘($)’, namely
‘\case
AtomF a -> return a
ConstantF x -> constant x
ApplicationF a b -> app a b’
|
32 | ConstantF x -> constant x
| ^^^^^^^^^^
Failed, no modules loaded.
Loaded GHCi configuration from /private/var/folders/s4/jhq2rgfd7z54466mw6xfzdm40000gn/T/ghci24303/ghci-script
{-# LANGUAGE TemplateHaskell, TypeFamilies, DeriveFunctor, DeriveFoldable, DeriveTraversable, FlexibleInstances #-}
{-# LANGUAGE LambdaCase, FlexibleContexts, UndecidableInstances #-}
module FreeNum where
import Data.Functor.Free
import Data.Functor.Foldable
import Data.Functor.Foldable.TH
class ExprClass a where
constant :: Int -> a
app :: a -> [a] -> a
foo :: Free ExprClass String
foo = return "5"
deriveInstances ''ExprClass -- here error
data Expression a
= Application (Expression a) [Expression a]
| Atom a
| Constant Int
deriving (Show, Eq, Functor)
makeBaseFunctor ''Expression
fromExpression :: Expression a -> Free ExprClass a
fromExpression = cata $ \case
AtomF a -> return a
ConstantF x -> constant x
ApplicationF a b -> app a b
instance ExprClass (Expression a) where
constant = Constant
app = Application
toExpression :: Free ExprClass a -> Expression a
toExpression = rightAdjunct Atom
resolver: nightly-2017-12-15
extra-deps:
- base-4.9.1.0
- syb-0.7
- template-haskell-2.11.1.0
- recursion-schemes-5.0.2
- algebraic-classes-0.8
- constraints-0.9
- free-functors-0.8.1
- free-4.12.4
- comonad-5.0.2
- cond-0.4.1.1
- containers-0.5.8.2
- data-partition-0.3.0.0
Version 1.6.1, Git revision f25811329bbc40b0c21053a8160c56f923e1201b (5435 commits) x86_64 hpack-0.20.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment