Forwarded from Zygohistomorphic Prepromorphism🇺🇦
можно считать это одним и тем же?
type family X (p :: Type) :: Type
class X (p :: Type) (a :: Type) | p -> a
Forwarded from Zygohistomorphic Prepromorphism🇺🇦
в обще на TF я могу такое написать, а вот с FD пока не понял как
type family Ext (p :: Type) :: Type
data Ast p
= Add (Ast p) (Ast p)
| Num Integer
| Other (Ext p)
class EvalAst p where
evalAst :: (Ast p -> Integer) -> Ext p -> Integer
data Expr
type instance Ext Expr = Void
instance EvalAst Expr where
evalAst _ x = absurd x
data Mul p = Mul (Ast p) (Ast p)
data MulExpr
type instance Ext MulExpr = Mul MulExpr
instance EvalAst MulExpr where
evalAst go (Mul x y) = go x * go y
eval :: forall p. EvalAst p => Ast p -> Integer
eval = go where
goAst = evalAst @p go
go (Add x y) = go x + go y
go (Num i) = i
go (Other x) = goAst x
main :: IO ()
main = do
print $ eval (Add (Num 20) (Num 10) :: Ast Expr)
Forwarded from Zygohistomorphic Prepromorphism🇺🇦
почему тут не может быть выведен функтор?
class Functor t => ExtF p t a | p -> t a
data AstF p a
= ValF Int
| AddF a a
| OtherF (forall t. ExtF p t a => t a) deriving Functor
Forwarded from Zygohistomorphic Prepromorphism🇺🇦
Couldn't match type ‘b’ with ‘a’
arising from a functional dependency between constraints:
‘ExtF p t a’ arising from a use of ‘a1’ at <playground>:8:51-57
‘ExtF p t b’
arising from a type expected by the context:
forall (t :: * -> *). ExtF p0 t a0 => t a0
Forwarded from Dmitry
Функтором мы можем тип a поменять на произвольный b. А dependency выполняться не будут
Forwarded from Zygohistomorphic Prepromorphism🇺🇦
и как тогда сделать? я помнимаю, что FD жестко захватили зависимость типов
Forwarded from Zygohistomorphic Prepromorphism🇺🇦
хочу, чтобы выводился функтор для моего типа
Forwarded from Dmitry
Может такое имеется в виду:
class Functor f => ExtF p f | p -> f
data A p a = A (forall t. ExtF p t => t a) deriving Functor
Forwarded from Dmitry
С TF получилось так:
type family ExtF' p :: * -> *
data A p a = A (Functor (ExtF' p) => ExtF' p a)
deriving instance Functor (A p)
Forwarded from Oleg Andreev
@Psilon а ты знаком с чуваком Varkor? https://varkor.github.io/blog/2019/03/28/idiomatic-monads-in-rust.html
varkor’s blog
Idiomatic monads in Rust
A pragmatic new design for high-level abstractions Monads (and, more generally, constructs known as “higher kinded types”) are a tool for high-level abstraction in programming languages1. Historically, there has been a lot of debate inside (and outside) the…
Forwarded from Oleg Andreev
varkor’s blog
Feasible functors in Rust
withoutboats, one of the Rust language design team, recently posted a thread on the infeasibility of monads as a useful abstraction technique in Rust, as a response to the persistence of some (usually from outside the Rust community) in claiming that “Rust…
Forwarded from hirrolot
Пользуясь случем, скину эту статью: https://habr.com/en/post/448240/
Хабр
Магические трансформации типов данных в Rust: Интринсика mem::transmute<T, U>
Введение Язык программирования Rust, невзирая на всеохватывающую идеологию безопасности данных, располагает и небезопасными методиками программирования, ведь по...