Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3673162
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:41:55+00:00 2026-05-19T02:41:55+00:00

I have written this method which given a number and a list will return

  • 0

I have written this method which given a number and a list will return a new list with the number inserted into the list at the correct position based on its value. (I’m doing an Insertion sort.)

let rec insertinto number numbers =
  match numbers with
  | [] -> [number]
  | head::tail -> if head > number then number::numbers else head::(insertinto number tail)

F# guesses the type of this method to be :

val insertinto : 'a -> 'a list -> 'a list when 'a : comparison

If I test this method with

[4; 10; 15] |> insertinto 12

I get

val it : int list = [4; 12; 10; 15]

Which is clearly wrong. The comparison ‘head > number’ is not working correctly.

To get it to work I have to specify the type of the numbers parameter :

let rec insertinto number numbers: int list =

Then it all works, but I dont want to use an int list all the time, I want this to work with any type of list. As long as the type implements comparison it should work, surely.

Why would this work with an int list and not a generic list? What am I missing?

edit

ok, this appears to be a Mono only problem.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:41:55+00:00Added an answer on May 19, 2026 at 2:41 am

    I just tested the code on Mac using Mono (version 2.8) and MonoDevelop with the latest F# integration and the first function (without type annotations) works as expected.

    However, I wouldn’t be too surprised if this was a bug in earlier version of Mono. There were all sorts of issues in 2.6.x. Giving incorrect result is weird error (more common was some error message or crash), but it may be caused by some issue. Can you check your version of Mono?

    I’m using this and it works fine:

    fsmac:~ tomaspetricek$ mono -V
    Mono JIT compiler version 2.8 (tarball Thu Oct  7 12:23:27 MDT 2010)
    Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.com
    

    Although you can run F# on Mono 2.6.x, it is highly recommended to use 2.8 (which fixes many issues with generics that were blocking for F#)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written this clone method for when the parent of the Employee class
i have written a method in java like this public boolean ADD(String ID,String Name,String
I have written a login form, in this I have used, form and method
I have a method somewhat similar to the one written bellow(this is just a
I have a method written in VB.NET. It looks like this: Shared Sub SomeMethod(ByVal
have written this little class, which generates a UUID every time an object of
I have written this function to auto correct gender to M or F from
I'm working on a website which will be hosting a number of books written
I'm attempting to create a method which will round nullables to a given decimal
I have a method which is used to check if the given class is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.