F#类型声明可能ala Haskell? [英] F# Type declaration possible ala Haskell?
问题描述
在F#ala Haskell中声明类型定义似乎是不可能的: 'haskell type def:
myFunc :: int - > int
我想在F#中使用这种type-def风格--FSI很乐意回显回到我身边:
fsi>让myType x = x +1 ;;
val myType:int - > int
我想在Haskell中明确F#类型的def签名。有没有办法做到这一点?我想用F#编写:
//无效F#
myFunc:int - > int
myFunc x = x * 2
如果要将可读类型声明与实现分开,可以使用'fsi'文件(F#签名文件)。 'fsi'只包含类型,通常也包含注释 - 你可以在F#库的源代码中看到一些很好的例子。您可以创建两个文件:
// Test.fsi
val myFunc:int - > int
// Test.fs
let myFunx x = x + 1
这适用于已编译的项目,但您不能在F#Interactive中轻松使用此方法。
I've looked a number of sources: it seems not possible to declare a type definition in F# ala Haskell:
' haskell type def:
myFunc :: int -> int
I'd like to use this type-def style in F#--FSI is happy to echo back to me:
fsi> let myType x = x +1;;
val myType : int -> int
I'd like to be explicit about the type def signature in F# as in Haskell. Is there a way to do this? I'd like to write in F#:
//invalid F#
myFunc : int -> int
myFunc x = x*2
If you want to keep readable type declarations separately from the implementation, you can use 'fsi' files (F# Signature File). The 'fsi' contains just the types and usually also comments - you can see some good examples in the source of F# libraries. You would create two files like this:
// Test.fsi
val myFunc : int -> int
// Test.fs
let myFunx x = x + 1
This works for compiled projects, but you cannot use this approach easily with F# Interactive.
这篇关于F#类型声明可能ala Haskell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!