例如,在列表monad绑定操作中:
xs >>= f = concat (map f xs)
Run Code Online (Sandbox Code Playgroud)
f的论据是什么?粘合剂?映射器?变压器?
Ruby callcc捕获当前的延续,随后可以调用它来恢复控件,但不能恢复数据.我想捕获当前的延续以及当前的内存图像.
在我看来,抓住堆应该不是很困难; 我可以依靠ObjectSpace::each_object和ObjectSpace::dump_all,或Marshal.dump,或简单地Object.clone.但是,我没有看到任何简单的方法来恢复堆.理想情况下,我想遍历object_id -> object 地图,为每个地图恢复对象的旧图像object_id(object_id如果相应的对象已经过GC ,则重新添加).不出所料,没有Ruby级别的api可以让我这样做.我想知道是否有任何我可以使用的Ruby GC的低级钩子.
任何帮助表示赞赏,包括有关替代方法的建议.
我试图用(偶数/奇数)奇偶性类型标记规范的Nat数据类型,看看我们是否可以获得任何自由定理.这是代码:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
-- Use DataKind promotion with type function for even-odd
module EvenOdd where
data Parity = Even | Odd
-- Parity is promoted to kind level Parity.
-- Even & Odd to type level 'Even & 'Odd of kind Parity
-- We define type-function opp to establish the relation that
-- type 'Even is opposite of 'Odd, and vice-versa
type family Opp (n :: Parity) :: Parity
type …Run Code Online (Sandbox Code Playgroud) 我有一个简单的长度索引向量类型和append长度索引向量函数:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
module LengthIndexedList where
data Zero
data Succ a
type family Plus (a :: *) (b :: *) :: *
type instance Plus Zero b = b
type instance Plus (Succ a) b = Succ (Plus a b)
data Vec :: * -> * -> * where
VNil :: Vec a Zero
VCons :: a -> Vec a n -> Vec a …Run Code Online (Sandbox Code Playgroud) 一阶逻辑的有效命题 (EPR) 片段通常被定义为以下形式的 prenex 量化公式集\xe2\x88\x83X.\xe2\x88\x80Y.\xce\xa6(X,Y),其中X和Y是(可能为空)变量序列。量化的顺序(即 )\xe2\x88\x83*\xe2\x88\x80*对于 EPR 的可判定性重要吗?如果改变量化顺序,我们会失去可判定性吗?
特别是,我对捕获可判定逻辑中的 set-monadic 绑定操作的语义感兴趣。给定S1类型的元素集T1(即S1具有类型)和类型的T1 Set函数,set-monad 的绑定操作通过应用于每个元素来构造一个新的类型集fT1 -> T2 SetS2T2 SetfS1并联合结果集可以在以下 SMT-LIB 代码/公式中捕获此行为:
(declare-sort T1)\n(declare-sort T2)\n;; We encode T1 Set as a boolean function on T1\n(declare-fun S1 (T1) Bool)\n(declare-fun S2 (T2) Bool)\n;; Thus, f becomes a binary predicate on (T1,T2)\n(declare-fun f (T1 T2) Bool)\n(assert (forall ((x T1)(y T2)) (=> …Run Code Online (Sandbox Code Playgroud) 这是代码:
module type S = sig
type t
val do_it: t -> int -> t
end
let rec foo (type a) (module Foo:S with type t=a) (i:int) (x:a) =
if i=0 then x
else foo (i-1) (Foo.do_it x i)
Run Code Online (Sandbox Code Playgroud)
我收到此类型错误(在第 8 行,字符 17-32):
Error: This expression has type a but an expression was expected of type 'a
The type constructor a would escape its scope
Run Code Online (Sandbox Code Playgroud)
这是意外的,因为类型构造函数a仍在其范围内。我希望函数 foo 具有以下类型:
foo: (module S with type t = 'a) -> int …Run Code Online (Sandbox Code Playgroud)