Hi,

A piece of code concerning printf formats is in the compiler, in order to get static typing. So you can't get such behaviour.

However, if you use dynamic features, you can get something similar, but it's unsafe of course (you might get type errors at run-time). For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
let foo (s: string) (ivalue: int) (svalue: string) =

  if s.[0] = 'i' then unbox (box ivalue)

  else unbox (box svalue)


> 10 + foo "i" 3 "world!";;

val it : int = 13

> "Hello " + foo "s" 3 "world!";;

val it : string = "Hello world!"

You might sometimes need explicit type annotations. Please note that this kind of code iis not recommended. Can't you find another solution?

About printf, see also:

[link:cs.hubfs.net]

Laurent.

By on 10/5/2008 5:30 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper