let rect = new Rectangle(x, y, sprite.Width, sprite.Height)
rect.X <- 888
Run Code Online (Sandbox Code Playgroud)
第二行在F#中失败,但在C#中,赋值有效.我不知道为什么.
postulate
extensionality : ? {A B : Set} {f g : A ? B}
? (? (x : A) ? f x ? g x)
-----------------------
? f ? g
Run Code Online (Sandbox Code Playgroud)
我知道上面的定义是一致的,但是如果稍微改动一下呢?
postulate
extensionality' : ? {A : Set} {B : A ? Set} {f g : (x : A) ? B x}
? (? (x : A) ? f x ? g x)
-----------------------
? f ? g
Run Code Online (Sandbox Code Playgroud)
为了解决 PLFA 书中的一个练习,我必须定义它,但我不确定这样做是否正确。我认为这应该是一致的,但我目前没有一个很好的方法来推理这一点,所以我想在这里问一下。
open import Data.Nat using (?;suc;zero)
open import Data.Rational
open import Data.Product
open import Relation.Nullary
open import Data.Bool using (Bool;false;true)
halve : ? ? ?
halve zero = 1?
halve (suc p) = ½ * halve p
?-halve : ? {a b} ? 0? < a ? a < b ? ?[ p ] (halve p * b < a)
?-halve {a} {b} 0<a a<b = h 1 where
h : ? ? ?[ p ] (halve p * b < …Run Code Online (Sandbox Code Playgroud) 码:
type Result = string option
type Parser<'a> = string -> int -> ('a -> Result) -> ('a -> Result) -> Result
let win r = Some <| "Correct: " + r
let lose _ = None
let parse_a: Parser<char> = fun text i win_cps lose_cps ->
let x = text.[i]
if x = 'a' then win_cps x else lose_cps x
let parse_many: Parser<char> -> Parser<char list> = fun p text i win_cps lose_cps ->
let rec loop: char list …Run Code Online (Sandbox Code Playgroud) 我试图追踪内存损坏错误,我设法得到了大部分的方式.事实证明,ManagedCuda的CudaDeviceVariable类为每个bool元素分配4个字节,而我强烈怀疑F#的本机数组每个bool元素只占用1个字节.该CopyToHost函数假定源和目标的大小相同,导致它写入数组的末尾.
我希望编译器告诉我F#bool []实际上是每个元素1个字节,所以我有最终的证明,并用它来替换错误的ManagedCuda库函数来计算大小.
怎么可能这样呢?
以下示例来自《软件基础》一书的 Poly 章节。
Definition fold_length {X : Type} (l : list X) : nat :=
fold (fun _ n => S n) l 0.
Theorem fold_length_correct : forall X (l : list X),
fold_length l = length l.
Proof.
intros.
induction l.
- simpl. reflexivity.
- simpl.
Run Code Online (Sandbox Code Playgroud)
1 subgoal
X : Type
x : X
l : list X
IHl : fold_length l = length l
______________________________________(1/1)
fold_length (x :: l) = S (length l)
Run Code Online (Sandbox Code Playgroud)
我希望它能简化左侧的步骤。当然应该可以。
Theorem fold_length_correct : forall …Run Code Online (Sandbox Code Playgroud) 我知道apply f in H可以用来将假设应用于函数,并且我知道apply f with a b c可以用来提供在直接应用时无法自行推断的参数f。
是否可以以某种方式结合使用两者?
现在,我要从软件基础中继续前进,在软件基础中,一切都放在盘子上,我很难弄清楚如何建立自己的项目。那里有一些说明,但由于我刚刚开始,在尝试设置 hello world 程序时我发现这太复杂了。我还有其他一些问题。
hello.v
Run Code Online (Sandbox Code Playgroud)
我成功编译空文件的方法hello.v是将以上内容放入_CoqProject文件中,然后运行...
coq_makefile -o Makefile.coq -f _CoqProject
Run Code Online (Sandbox Code Playgroud)
这会生成 makefile。
make -f Makefile.coq
Run Code Online (Sandbox Code Playgroud)
这会编译项目,但我无法make hello仅使用它,而 Proof General 在编译单个文件时恰好使用它。
make hello.vo
make: *** No rule to make target 'hello.vo'. Stop.
Run Code Online (Sandbox Code Playgroud)
以上是我尝试从 Proof General 进行编译时得到的结果。
我应该在这里做什么?使用空文件设置项目以与 Proof General + Emacs 一起使用的最简单的方法是什么?
-Q . VFA
Run Code Online (Sandbox Code Playgroud)
另外,为什么《科幻小说》第 3 卷尽管文件内容不多,但仍然有效_CoqProject?它只有以上这些。
test :: VM.MVector s Int -> Int
test x = runST $ do
a <- return x
VM.read a 0 -- Type error
Run Code Online (Sandbox Code Playgroud)
我试图弄清楚如何不将ST monad中的所有内容都放入单个函数中.如果我试图修改x或返回一个值,编译器会抱怨可变向量的状态部分不匹配.
是否可以在Haskell中对传递的可变向量进行操作,或者在对它们执行任何操作之前是否必须将它们冻结为不可变对应的?
编辑:
这是实际的错误.
Couldn't match type `s1' with `s'
`s1' is a rigid type variable bound by
a type expected by the context: ST s1 Int at rjb.hs:17:12
`s' is a rigid type variable bound by
the type signature for test :: VM.MVector s Int -> Int
at rjb.hs:16:11
Expected type: VM.MVector
(Control.Monad.Primitive.PrimState …Run Code Online (Sandbox Code Playgroud) type AdderType() =
/// Appends to the container.
static member (+)
(cont:DockPanel,child:#UIElement) =
cont.Children.Add child |> ignore
child
Run Code Online (Sandbox Code Playgroud)
当我像上面那样上课并尝试这样的事情.
let dock = DockPanel()
let win = Window(Title = "Check the Window Style", Content = dock)
let menu = dock + Menu()
Run Code Online (Sandbox Code Playgroud)
我得到的错误是None of the types 'DockPanel,Menu' support the operator '+'.我受到启发,由Phil Trelford的绑定示例制作上述内容,如下所示:
type DependencyPropertyValuePair(dp:DependencyProperty,value:obj) =
member this.Property = dp
member this.Value = value
static member (+)
(target:#UIElement,pair:DependencyPropertyValuePair) =
target.SetValue(pair.Property,pair.Value)
target
Run Code Online (Sandbox Code Playgroud)
以上由于某种原因起作用.我不知道为什么.是否有可能重载+或其他一些操作符,以便我可以优雅地添加控件到容器?