Specifying type of parameter in F# function declaration

耗尽温柔 提交于 2019-12-11 08:00:07

问题


I am just starting out with F# so this is a bit of basic question on best practise with type inference.

I am trying to write a function that works on a TimeSpan. This is a simplified version of what I am trying to do:

let intervalsFromTimespan t = t.TotalMinutes / 5.0 

Clearly this won't work because I need to somehow state that t is a timespan.

Would the correct way be:

let intervalsFromTimespan' t = (t : TimeSpan).TotalMinutes / 5.0

回答1:


Try this:

let intervalsFromTimespan (t : TimeSpan) = t.TotalMinutes / 5.0


来源:https://stackoverflow.com/questions/20128088/specifying-type-of-parameter-in-f-function-declaration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!