小编Wal*_*lly的帖子

F#Monad如何修复数据类型

我正在尝试用F#写一个Monad但是我无法编译代码而且我收到错误FS0001错误:这个表达式预计会有类型'Result'但是这里有类型'(Result <'a> - > Result << b>) - >结果<'b>'

open System
type Result<'TSuccess> =
     | Success of 'TSuccess
     | Failure

let bind x f = 
    match x with 
    |  Success x -> f (Success x)
    | Failure -> Failure



let stringToInt (s:string) = 
    try
       let result = s |> int
       Success result 
    with 
       |_-> Failure 

let isPositive (i:int)  = 
    if ( i >  0) then  Success i : Result<int>
    else Failure 

let toString (i:int) = 
    try
       let result = i …
Run Code Online (Sandbox Code Playgroud)

monads f#

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

标签 统计

f# ×1

monads ×1