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 7549127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:52:22+00:00 2026-05-30T09:52:22+00:00

I suspect that I am missing something very obvious here but this doesn’t work:

  • 0

I suspect that I am missing something very obvious here but this doesn’t work:

let t = Array2D.create 1 1 1.0
for x in t do printfn "%f" x;;

It fails with

error FS0001: The type ‘obj’ is not compatible with any of the types float,float32,decimal, arising from the use of a printf-style format string

Interestingly using printf "%A" or "%O" prints the expected values which suggests to me that the problem is with the type inference

The corresponding code for a 1D array works fine

let t = Array.create 1 1.0
for x in t do printfn "%f" x;;

For reference this is on version 2.0 (both interactive and compiler) running on the latest mono

  • 1 1 Answer
  • 0 Views
  • 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-30T09:52:23+00:00Added an answer on May 30, 2026 at 9:52 am

    In .NET, a 1D array implicitly implements IList, which means it also implements (by inheritance) IEnumerable<T>. So, when you run:

    let t = Array.create 1 1.0
    for x in t do printfn "%f" x;;
    

    the F# compiler emits code which gets an implementation of IEnumerable<T> (seq<T> in F#) from t, then iterates over it. Since it’s able to get an IEnumerable<T> from the array, x will have type T.

    On the other hand, multi-dimensional arrays (2d, 3d, etc.) only implement IEnumerable (not IEnumerable<T>) so the F# compiler infers the type of x as System.Object (or obj, in F#).

    There are two solutions for what you want:

    Cast each individual value within the loop, before printing it:

    for x in t do printfn "%f" (x :?> float);;
    

    Or, use Seq.cast to create and iterate over a strongly-typed enumerator:

    for x in (Seq.cast<float> t) do printfn "%f" x;;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I suspect I'm missing something rather basic, yet I can't figure this one out.
I've been looking at this issue for too long. I suspect I'm missing something
I suspect this applies to general ASP.Net too but I am not sure. If
I'll eat my hat if I get a good answer to this...I suspect that
I'm suddenly missing the empty class template. I suspect that it is because of
For the sake of this question, let us suppose that I want a row
I suspect that one of my applications eats more CPU cycles than I want
I suspect that calls from separate threads (>15) are having a negative effect on
I suspect that adding a certain letter/character to the beginning of my text will
My company has a problem: we suspect that the NACHA files we are receiving

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.