小编use*_*465的帖子

为什么我们需要容器?

(作为借口:标题模仿了为什么我们需要monad?)

容器(和索引的)(和无用的)和描述.但是容器是有问题的,根据我很小的经验,就容器而言,比描述更难以思考.非索引容器的类型是同构的?- 这是非常不明确的.形状和位置描述有帮助,但在

?_?? : ? {? ? ?} -> Container ? ? -> Set ? -> Set (? ? ? ? ?)
? Sh ? Pos ?? A = ? ? sh -> Pos sh -> A

K? : ? {? ?} -> Set ? -> Container ? ?
K? A = A ? const (Lift ?)
Run Code Online (Sandbox Code Playgroud)

我们本质上是使用?而不是形状和位置.

容器上的严格正面免费monad的类型有一个相当简单的定义,但Freermonad 的类型对我来说看起来更简单(在某种意义上,Freer …

haskell type-theory generic-programming agda dependent-type

35
推荐指数
1
解决办法
1116
查看次数

何时在Haskell中使用CPS vs密度与反射无悔

在Haskell中创建monad 时,是否有任何关于何时使用延续传递样式密度反射而没有悔恨的经验法则?

举个例子,我将使用一个简单的协程monad.如果您以前从未见过这个,可能需要查看Monad.Reader Issue 19中的"Coroutine Pipelines"文章或管道库.可以在此存储库中找到以下示例的完整代码.

  1. 正常

    这只是一个定义为数据类型的普通monad:

    data FooM i o a
      = Await (i -> FooM i o a)
      | Yield o (FooM i o a)
      | Done a
    
    Run Code Online (Sandbox Code Playgroud)

    这种风格被广泛用于Haskell生态系统.这种风格的一个例子是Proxy来自的数据类型pipes.

  2. 延续传球风格(CPS)

    这类似于普通样式,但每个数据构造函数都成为延续的参数:

    newtype FooCPS i o a = FooCPS
      { runFooCPS
          :: forall r.
             ((i -> FooCPS i o a) -> r)
          -> (o -> FooCPS i o a -> …
    Run Code Online (Sandbox Code Playgroud)

reflection monads continuations haskell free-monad

25
推荐指数
1
解决办法
1068
查看次数

通过效果进行通用编程

在Idris 效果库中,效果表示为

||| This type is parameterised by:
||| + The return type of the computation.
||| + The input resource.
||| + The computation to run on the resource given the return value.
Effect : Type
Effect = (x : Type) -> Type -> (x -> Type) -> Type
Run Code Online (Sandbox Code Playgroud)

如果我们允许资源成为值并交换前两个参数,我们得到(其余代码在Agda中)

Effect : Set -> Set
Effect R = R -> (A : Set) -> (A -> R) -> Set
Run Code Online (Sandbox Code Playgroud)

拥有一些基本的类型 - 上下文 - 会员机制

data Type : Set …
Run Code Online (Sandbox Code Playgroud)

haskell generic-programming agda dependent-type idris

21
推荐指数
1
解决办法
1701
查看次数

观测类型理论中的模式匹配

走向观察类型理论的"5.完整OTT"部分的最后,作者展示了如何在OTT中定义可构造的构造函数索引数据类型.这个想法基本上是将索引数据类型转换为参数化,如下所示:

data IFin : ? -> Set where
  zero : ? {n} -> IFin (suc n)
  suc  : ? {n} -> IFin n -> IFin (suc n)

data PFin (m : ?) : Set where
  zero : ? {n} -> suc n ? m -> PFin m
  suc  : ? {n} -> suc n ? m -> PFin n -> PFin m
Run Code Online (Sandbox Code Playgroud)

康纳还在观察类型理论(交付)的底部提到了这种技术:

当然,解决方法是做GADT人员所做的事情,并明确地将归纳家族定义为命题平等.当然,你可以通过变性来运输它们.

但是,Haskell中的类型检查器知道范围中的等式约束,并且在类型检查期间实际使用它们.我们可以写

f :: a ~ b => a -> b
f x …
Run Code Online (Sandbox Code Playgroud)

haskell type-theory agda gadt observational-type-theory

15
推荐指数
1
解决办法
636
查看次数

为什么不从Prelude"迭代"打结?

为什么没有iterate定义为

iterate :: (a -> a) -> a -> [a]
iterate f x = xs where xs = x : map f xs
Run Code Online (Sandbox Code Playgroud)

在序曲?

haskell tying-the-knot

8
推荐指数
2
解决办法
147
查看次数

Agda中的Arity-generic编程

如何在Agda中编写arity-generic函数?是否可以编写完全依赖和Universe多态的arity-generic函数?

generic-programming agda arity dependent-type

6
推荐指数
1
解决办法
511
查看次数

这件事与KleisliFunctor类似?

以下是我们如何定义KleisliFunctor:

class (Monad m, Functor f) => KleisliFunctor m f where
  kmap :: (a -> m b) -> f a -> f b
  kmap f = kjoin . fmap f

  kjoin :: f (m a) -> f a
  kjoin = kmap id
Run Code Online (Sandbox Code Playgroud)

这是类型类吗?

class (Functor f, Monad m) => Absorb f m where
  (>>~) :: f a -> (a -> m b) -> m b
  a >>~ f = ajoin $ fmap f a

  ajoin :: f (m …
Run Code Online (Sandbox Code Playgroud)

monads haskell typeclass category-theory

6
推荐指数
1
解决办法
160
查看次数

为什么索引镜头的定义方式如何?

这个reddit线程中有一些非常有用的解释,如何定义索引镜头,但我想知道细节.

因此,重点是索引镜头的定义使得它们也可以被视为非索引镜头.这两个类负责:

class (Choice p, Corepresentable p,
       Comonad (Corep p), Traversable (Corep p),
       Strong p, Representable p, Monad (Rep p),
       MonadFix (Rep p), Distributive (Rep p),
       ArrowLoop p, ArrowApply p, ArrowChoice p
       ) => Conjoined p where
  distrib :: Functor f => p a b -> p (f a) (f b)
  conjoined :: (p ~ (->) => q (a -> b) r) -> q (p a b) r -> q (p a b) r

class Conjoined p => …
Run Code Online (Sandbox Code Playgroud)

haskell haskell-lens

6
推荐指数
0
解决办法
129
查看次数

世界还不够

我仍然试图将观测类型理论本身和整个事物嵌入到Agda中.

目前我有以下Universe层次结构:

Prop : Type 0 : Type 1 : ...
(? ? -> Type ?) : Type ?? : Type ??
Run Code Online (Sandbox Code Playgroud)

为了定义宇宙多态函数的相等性,我需要添加一个代码Type ??,这迫使我添加Type ??到元理论中.在上一个问题中有更多相关内容.

以下是解释算子将类型提升到元理论的基本目标理论函数?_?.

mutual
  Eq : ? (?? lev ? ? -> ?? lev ? ? -> univ? ? ? univ? ? ? prop) ?
  eq : ? (?? lev ? ? -> ?? lev ? ? -> ? (univ? ?) ? A -> ? (univ? ?) …
Run Code Online (Sandbox Code Playgroud)

type-theory agda dependent-type observational-type-theory

5
推荐指数
0
解决办法
189
查看次数

如何在线性时间内通过`Fin`枚举列表的元素?

我们可以枚举列表的元素,如下所示:

-- enumerate-? = zip [0..]
enumerate-? : ? {?} {A : Set ?} -> List A -> List (? × A)
enumerate-? = go 0 where
  go : ? {?} {A : Set ?} -> ? -> List A -> List (? × A)
  go n  []      = []
  go n (x ? xs) = (n , x) ? go (?.suc n) xs
Run Code Online (Sandbox Code Playgroud)

Eg enumerate-? (1 ? 3 ? 2 ? 5 ? [])等于(0 , 1) ? …

time-complexity agda dependent-type idris

4
推荐指数
1
解决办法
395
查看次数

OTT中可证明的连贯性

我正在玩观察型理论.

这里是强制相互定义的?-types(?是小写?,即? A B代码(x : A) -> B x)的相等性:

? A? B? ? ? A? B? = ? (A? ? A?) ? P -> ? _ ? x -> B? (coerce P x) ? B? x
Run Code Online (Sandbox Code Playgroud)

和相应定义的函数相等(?是小写?):

_?_ {A = ? A? B?} {? A? B?} f? f? = ? (A? ? A?) ? P -> ? _ ? x -> f? (coerce P …
Run Code Online (Sandbox Code Playgroud)

type-theory agda dependent-type observational-type-theory

4
推荐指数
1
解决办法
321
查看次数

消除类型级别的Maybe

有没有办法Maybe在类型级别解包monad中的值?例如,如何tailVec具有以下变体的s 定义类型安全pred:

pred : ? -> Maybe ?
pred  0      = nothing
pred (suc n) = just n
Run Code Online (Sandbox Code Playgroud)

?就像是

tail : ? {n ?} {A : Set ?} -> Vec A n ->
  if isJust (pred n) then Vec A (from-just (pred n)) else ?
Run Code Online (Sandbox Code Playgroud)

这个例子完全是人为的,但并不总是可以摆脱一些前提条件,所以你可以通过构造定义来编写一个正确的,比如tail标准库中的函数:

tail : ? {a n} {A : Set a} ? Vec A (1 + n) ? Vec A n
tail (x ? xs) = …
Run Code Online (Sandbox Code Playgroud)

agda dependent-type

3
推荐指数
1
解决办法
146
查看次数

实例搜索限制

实例论证机制在旧论文Agda维基中描述.这些消息来源没有提到一些值得注意的事实吗?实例搜索有哪些限制?

agda

2
推荐指数
1
解决办法
127
查看次数