Forwarded from Αλεχ Zhukovsky
symbols = ['a', 'b', 'c']
values = [1, 2, 3]
for x in symbols:
print(x)
squared = [x*x for x in values] # Все плохо. "x" из верхнего "for" затёрт
print(x)Вывод программы будет следующим:
a
3
b
3
c
3Forwarded from Oleg Andreev via @gif
This media is not supported in your browser
VIEW IN TELEGRAM
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)