【问题标题】:error FS0001: Type mismatch. Expecting a 'a -> int but given a 'a -> unit错误 FS0001:类型不匹配。期望一个 'a -> int 但给定一个 'a -> unit
【发布时间】:2014-07-26 01:30:26
【问题描述】:

收到错误:

"error FS0001: Type mismatch. Expecting a 'a -> int but given a 'a -> unit"

我正在为以下代码使用 Sublime 文本:

namespace eulers
module problems =   

open System.Numerics

[<EntryPoint>]
let main args =
  let isPrime n = [2L..int64 (sqrt (float n))] |> Seq.exists(fun x -> n % x = 0L) |> not 

  let p1 = [1..999] |> Seq.filter(fun x -> x % 3 = 0 || x % 5 = 0) |> Seq.sum

  let p2 = Seq.unfold(fun(x,y) -> Some(x, (y, x + y))) (0L, 1L) |> Seq.takeWhile(fun x -> x < 4000000L) |>     Seq.filter(fun x -> x % 2L = 0L) |> Seq.sum

  let p3 = [2L.. int64 (sqrt (float 600851475143L))] |> Seq.filter(fun x -> 600851475143L % x = 0L && isPrime x) |> Seq.max

  printf "%d" p1

【问题讨论】:

  • 在哪一行? - 具体说明您的错误

标签: f#


【解决方案1】:

请参阅 [&lt;EntryPoint&gt;] 上的 MSDN 文档 - 您需要从主函数返回 int

【讨论】:

  • 完美它工作,但另外,当我在 Sublimetext 中运行它时,它没有给我任何结果,
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-26
  • 2022-12-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多