posts - 255, comments - 292, trackbacks - 0

My Links

News

View Steve Michelotti's profile on LinkedIn

Twitter












Tag Cloud

Archives

Post Categories

Blend Bloggers

Bloggers that I follow

Books

F# Bloggers

F# Communities

F# Online Books

Fonts

HTML CSS ASP

Machine Learning

My Links

My Local UserGroups

My Online Presence

MY SA Links

Online Seminars

SA Software Companies

Web Design

F# int |> bigint

 

I had a bit of a no brainer yesterday… I have been using the forward pipe to convert values, and came up against the problem where the following code would work

let IntToFloat = 10 |> float
let FloatToInt = 10.0 |> int

But the equivalent bigint code would not work…

let FloatToBigint = 10.0 |> bigint

It was only after a few hours of reading up on type casting in F# and getting totally confused that I finally resulted to Stack Overflow. The answer was humbling…

The reason why FloatToBignint does not compile is because F# compiler is looking for a function called bigint that has an input of type float. Duh!

All along I was thinking that I needed to add some sort of overloading to the operator to allow bigint to accept the forward pipe and yet I had missed the obvious.

So as soon as I had the following function declared…

let bigint(x:float) = bigint(x)

 

the code…

let FloatToBigint = 10.0 |> bigint

works perfectly…

thank you Stack Overflow!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Thursday, July 01, 2010 5:44 PM | Filed Under [ F# ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: