F# How to write a function that takes int list or string list : <p>I'm messing around in F# and tried to write a function that can take an <code>int list</code> or a <code>string list</code>. I have written a function that is logically generic, in that I can modify nothing but the type of the argument and it will run with both types of list. But I cannot generically define it to take both.</p>

<p>Here is my function, without type annotation:</p>

<pre class="lang-ml prettyprint-override"><code>let contains5 xs =
    List.map int xs
    |&gt; List.contains 5
</code></pre>

<p>When I try to annotate the function to take a generic list, I receive a warning <code>FS0064: the construct causes the code to be less generic than indicated by the type annotations</code>. In theory I shouldn't need to annotate this to be generic, but I tried anyway.</p>

<p>I can compile this in two separate files, one with</p>

<pre class="lang-ml prettyprint-override"><code>let stringtest = contains5 ["1";"2";"3";"4"]
</code></pre>

<p>and another with</p>

<pre class="lang-ml prettyprint-override"><code>let inttest = contains5 [1;2;3;4;5]
</code></pre>

<p>In each of these files, compilation succeeds. Alternately, I can send the function definition and one of the tests to the interpreter, and type inference proceeds just fine. If I try to compile, or send to the interpreter, the function definition and both tests, I receive <code>error FS0001: This expression was expected to have type string, but here has type int</code>.</p>

<p>Am I misunderstanding how typing should work? I have a function whose code can handle a list of ints or a list of strings. I can successfully test it with either. But I can't use it in a program that handles both?</p>
