Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting first element from the tuple using "fst" throwing an error "type mismatch"

Tags:

tuples

f#

This is a tuple I have taken

 let person = ("Prathap Reddy SV", "Male", 16)
 let name = fst person   

 or 

 let person = ("Prathap", "Male", 16)
 let name = fst person  

When I compile this that is showing me the below output

 > let person = ("Prathap Reddy SV", "Male", 16)
   let name = fst person

   let name = fst person
   ---------------^^^^^^

   stdin(152,16): error FS0001: Type mismatch. Expecting a
   string * string    
 but given a
   string * string * int    
 The tuples have differing lengths of 2 and 3   

But When I give tuple with two string values it is working fine.

like image 739
Exception Avatar asked Dec 27 '11 12:12

Exception


1 Answers

The signature of fst is ('a * 'b -> 'a), that's why you receive the given error.

The function fst expects a tuple of two elements of whatever types, but you offer it a tuple of three elements. For tuple of three strings the error would be the same: fst ("a","b","c") will yield

stdin(1,6): error FS0001: Type mismatch. Expecting a
    'a * 'b    
but given a
    'a * 'b * 'c    
The tuples have differing lengths of 2 and 3
like image 80
Gene Belitski Avatar answered Nov 08 '22 08:11

Gene Belitski