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

  • Home
  • SEARCH
  • 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 3214702
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:05:31+00:00 2026-05-17T15:05:31+00:00

open System type Foo() = interface Collections.IEnumerable with member x.GetEnumerator () = null type

  • 0
open System

type Foo() =
     interface Collections.IEnumerable with
         member x.GetEnumerator () = null

type Bar() =
     interface Collections.IEnumerable with
         member x.GetEnumerator () = null
     interface Collections.Generic.IEnumerable<int> with
         member x.GetEnumerator () = null

let xs, ys = Foo(), Bar()

for x in xs do () // <--
for y in ys do () // fine

The code above produces the following compilation error:

The type 'Foo' is not a type whose values can be enumerated with this syntax, i.e. is not compatible with either seq<_>, IEnumerable<_> or IEnumerable and does not have a GetEnumerator method.

The code looks perfectly legal and the generic version works fine. Is this an F# compiler bug?

  • 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-17T15:05:31+00:00Added an answer on May 17, 2026 at 3:05 pm

    I think this is a mismatch between the error message an the specification. As kvb points out, the specification allows for ... in in only two cases:

    • When the type implements generic IEnumerable<_> interface (aka seq<_>)
    • When the type has a GetEnumerator method that returns type with certain properties

    If the type implements a non-generic IEnumerable interface then it doesn’t match any of the two conditions. However, if you cast it to IEnumerable then it will actually be the IEnumerable type, which matches the second condition. Having a GetEnumerator member directly in the type (as desco suggests) is also correct, because it also matches the second case.

    So, I think that the error message is incorrect, because it says that implementing non-generic IEnumerable is sufficient, but it is actually not.

    However, there seems to be one actual compiler error related to the for loop. You get a compiler “internal error” when you write the following code (which is not correct, because the inferred generic return type doesn’t implement IEnumerator):

     type Foo() =
       member x.GetEnumerator () = null
     for x in Foo() do ()  // Internal error here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following F# code fails because Type.DefaultBinder does not want to bind to the
Consider this scenario. I have an object, lets call it.... Foo. Foo raises a
How would you convert type Node into an immutable tree? This class implements a
So I'm working through a bit of a problem, and some advice would be
Gday All, I have been dabbling in some F# of late and I came
In my epic quest of making C++ do things it shouldn't, I am trying
I have tried to use this code in VS2008 (and may have included too
I'm trying to work my way through Compilers: Backend to Frontend (and Back to
Been working with a lot of TimeSpans recently, and have a need to get
We're gettin' hairy here. I've tested a bunch of tree-synchronizing code on concrete representations

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.