Yes, type constructors accept tuples, but they can be passed as value:

type toto = Toto of string * string

let toto = Toto

// val toto : string * string -> toto

It's quite common to write a small constructor function if you need to partially apply the construction of constructor, i.e

let toto s1 s2 = Toto(s1, s2)

Cheers,

Rob

By on 1/12/2009 1:44 AM ()

>>Yes, type constructors accept tuples, but they can be passed as value:

I am not sure this is accurate

type MyStringPair= MyStringPair of String * String

let stringTuple= ("Hello","World")

let result= MyStringPair stringTuple //generated compiler error

That is where my "why" question comes from... I have the impression that the type system "lies" or gives false signature when type constructors are concerned.

By on 1/12/2009 8:32 AM ()

To do that, declare MyStringPair like this. Note the (...) are significant.

1
2
3
type MyStringPair= MyStringPair of (String * String)
let stringTuple= ("Hello","World") 
let result= MyStringPair stringTuple
By on 1/12/2009 11:19 AM ()

great thank you. It works because the type constructor behaves well with a single parameter.

Still wondering about the type of the constructor without () and about why it was implemented with this special type.

String * String is a tuple of strings except in case of type constructors!

By on 1/12/2009 11:37 AM ()
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