首页 > 解决方案 > 在 F# 交互中,如何获取 [] 来自 List.map?

问题描述

总新手 F# 问题。

在 Visual Studio 2019,F# 交互式文件中,我有:

open System

module Visit =
    type Model =
        {
            Id: int
            Name: string
        }

    let init col cel =
        { 
            Id = col*100 + cel*10 + 1
            Name = sprintf "My Name is col: %d  cel: %d"  col cel       
        }

    let getName m = m.Name

module Cell =
    type Model =
        {
            Id: int
            Visit: Visit.Model
        }

    let init col cel =
        { 
            Id = col*10 + cel
            Visit = Visit.init col cel
        }

    let getVisit (m:Model) = Visit.getName m.Visit
        


module Column =
    type Model =
        {
            Id: int
            Appointments: Cell.Model list
        }

    let init =
        {   Id = 0
            Appointments = [0 .. 3] |> List.map (Cell.init 0)  }

    let findAppointment m =
         m.Appointments |> List.map ( fun cell -> Cell.getVisit)
        // m.Appointments |> List.map ( fun cell -> printfn "%A" cell; cell.Id) 
       

    let find =
        init |> findAppointment

我得到:

val find : (Cell.Model -> string) list = [fun:Invoke@3233; 有趣:调用@3233;有趣:调用@3233;有趣:调用@3233]

如何在列表中获取实际的名称(字符串)函数结果(不是 [fun:Invoke@...),...]???

TIA

标签: f#f#-interactive

解决方案


罪魁祸首是,这Cell.getVisit不适用于细胞,即它应该是

m.Appointments |> List.map (fun cell -> Cell.getVisit cell)

或者

m.Appointments |> List.map Cell.getVisit

推荐阅读