小编nic*_*las的帖子

fsharp中的fst和3元组

你知道最好的方法吗:

let toTableau2D (seqinit:seq<'a*'b*'c>) =
   let myfst = fun (a,b,c) -> a
   let myscd = fun (a,b,c) -> b
   let mytrd = fun (a,b,c) -> c

   let inputd = seqinit |> groupBy2 myfst myscd
Run Code Online (Sandbox Code Playgroud)

必须有一个比重写fst更好的方法..

更新 在pad建议之后,我重写了将之前的'a*'b打包成单个结构我的代码现在看起来像

let toTableau (seqinit:seq<'a*'b>) =
  let inputd = seqinit |> Seq.groupBy fst |> toMap
  let keys =  seqinit |> Seq.map fst |> Set.ofSeq |> List.ofSeq
  ...
Run Code Online (Sandbox Code Playgroud)

f# tuples cons iterable-unpacking

5
推荐指数
1
解决办法
1677
查看次数

关于FParsec处理空格的建议

我有以下子表达式来解析具有以下格式的"引号"

"5.75 @ 5.95"
Run Code Online (Sandbox Code Playgroud)

因此我有这个parsec表达式来解析它

let pquote x = (sepBy (pfloat) ((spaces .>> (pchar '/' <|>  pchar '@' )>>. spaces))) x
Run Code Online (Sandbox Code Playgroud)

它工作得很好..除非我的输入中有一个尾随空格,因为分隔符表达式开始消耗内容.所以我把它包裹在一次尝试中,根据我的理解,这看起来很像或多或少是这意味着什么成为.

let pquote x = (sepBy (pfloat) (attempt (spaces .>> (pchar '/' <|>  pchar '@' )>>. spaces))) x
Run Code Online (Sandbox Code Playgroud)

因为我不太了解fparsec,我想知道是否有更好的方法来写这个.它似乎有点沉重(当然仍然很容易管理)

f# fparsec

5
推荐指数
1
解决办法
708
查看次数

在F#中编写脚本文件的测试

我有一些脚本文件的功能,setup.fsx我想测试那些.xUnit和类似需要测试的函数是程序集的一部分.

所以我想将我的脚本从setup.fsx重命名为setup.fs扩展名,然后从另一个脚本文件加载它.但后来我的脚本依赖于

#r "System.Xml"
#r "System.Xml.Linq"
Run Code Online (Sandbox Code Playgroud)

然后我必须在调用脚本中指定(远离依赖实际出现的位置)

无论如何都要在xUnit worflow中集成基于脚本的测试吗?建议用什么组织编写脚本文件的测试?

(可能我们需要一个visual studio扩展,用于脚本中的测试而不是汇编...)

tdd f# xunit

5
推荐指数
1
解决办法
775
查看次数

F#中的对象表达和捕获状态

是什么让第一次实施KO?

type IToto  = 
    abstract Toto : unit -> unit

{ new IToto with  
      member this.Toto = 
             fun () -> () }

{ new IToto with  
        member this.Toto () = ()  }
Run Code Online (Sandbox Code Playgroud)

f# interface

5
推荐指数
1
解决办法
107
查看次数

数据绑定F#视图模型

在XAML编辑器中,我可以将命名空间设置为C#项目中包含的Viewmodel

namespace ViewModelDB
{
    public class DependencyViewModel : IViewModelDB
    {
        public string Message { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的xaml

<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:ViewModelDB="clr-namespace:ViewModelDB;assembly=ViewModelDB"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
        >
    <UserControl.DataContext>
        <ViewModelDB:DependencyViewModel/>
    </UserControl.DataContext>
    <Grid>
        <TextBlock Text="{Binding Message}"/>
    </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

然后识别绑定"消息".

当我指向类似选区的F#名称空间时

namespace ModuleDBGraph

open Infrastructure
open Microsoft.Practices.Prism.Regions;
open Microsoft.Practices.Unity;

type IDependencyViewModel =
    inherit IViewModel
    abstract Message : string with get, set

type DependencyViewModel () = 
    interface IDependencyViewModel with 
        member val Message = "" with get, set
Run Code Online (Sandbox Code Playgroud)

然后我松开了对绑定消息的识别

<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" …
Run Code Online (Sandbox Code Playgroud)

wpf xaml f#

5
推荐指数
1
解决办法
757
查看次数

在最不固定类型之后的haskell中的bifunctor

我不确定如何在定点之后派生出函数实例:

data FreeF f a next  = PureF a | FreeF (f next)  deriving (Functor)

data Mu f  = In { out :: f ( Mu f ) }

newtype Free f a = Free(  Mu (FreeF f a)  )

instance Functor f => Functor (Free f) where
     fmap h (Free (out -> PureF a))  = Free (In (PureF (h a)))
     fmap h (Free (out -> FreeF fn)) = Free (In (fmap undefined undefined)) --stuck
Run Code Online (Sandbox Code Playgroud)

如果我修改Mu以接受额外的类型参数,我可以继续...直到...:

data Mu f a …
Run Code Online (Sandbox Code Playgroud)

haskell functor recursive-datastructures free-monad

5
推荐指数
1
解决办法
144
查看次数

STM和输出IO

如果我位于事务失败的 STM 内部,并且我作为正常控制流的一部分重试(无 STM 冲突等),我可能想向外部人员指示采取纠正措施的方法。

如果是纯粹‘传出’的话,那我的STM还是可以纯粹重放的。

我如何通过 STM 重试执行传出IO?

有人遇到过这种情况吗?这有多邪恶?

concurrency events haskell stm

5
推荐指数
1
解决办法
522
查看次数

从 utop 检索文档

有没有办法直接从 utop 检索此处以 html 形式显示的文档。

\n\n

我可以通过使用获取类型

\n\n
utop # open Core;;\n\xe2\x94\x80( 10:41:50 )\xe2\x94\x80< command 4 >\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80{ counter: 0 }\xe2\x94\x80\nutop # #typeof "In_channel.input_char";;\nval Core.In_channel.input_char : Core.In_channel.t -> Base.char Base.option\n\xe2\x94\x80( 10:41:54 )\xe2\x94\x80< command 5 >\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80{ counter: 0 }\xe2\x94\x80\n
Run Code Online (Sandbox Code Playgroud)\n\n

或者

\n\n
utop # #show In_channel.input_char;;\nval input_char : in_channel -> char option\n\xe2\x94\x80( 10:43:00 )\xe2\x94\x80< command 7 >\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80{ counter: 0 }\xe2\x94\x80\nutop #\n
Run Code Online (Sandbox Code Playgroud)\n\n

但医生更丰富

\n\n
  val input_char : t \xe2\x80\x91> Stdio__.Import.char Stdio__.Import.option\n\nRead one character from the given input channel. \nReturn None …
Run Code Online (Sandbox Code Playgroud)

ocaml utop

5
推荐指数
1
解决办法
998
查看次数

让我们记住值,并让我们记住ocaml中的函数

为什么第一个定义会被拒绝的最佳直觉是什么,而第二个定义会被接受?

let rec a = b (* This kind of expression is not allowed as right-hand side of `let rec' *)
and b x = a x

let rec a x = b x (* oki doki *)
and b x = a x
Run Code Online (Sandbox Code Playgroud)

它是否与2种减少方法相关联:每个函数替换(和Rec定界符)的一个规则VS每个函数定义一个规则(和lambda提升)?

ocaml

5
推荐指数
1
解决办法
150
查看次数

Haskell 中的约束、函数组合和 let 抽象

关于为什么ko1ko2失败有一个简单的解释吗?

{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module SOQuestionExistential where

import Data.Proxy

------------------------------------------------------------------------------

class C s where
  important_stuff :: proxy s -> a

compute_ok :: forall r. (forall s. C s => Proxy s -> IO r) -> IO r
compute_ok k = undefined

unref_ok :: Proxy s -> Proxy s -> IO ()
unref_ok _ _ = return ()

----

ok :: (forall s. C …
Run Code Online (Sandbox Code Playgroud)

haskell

5
推荐指数
1
解决办法
104
查看次数