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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:44:47+00:00 2026-06-15T10:44:47+00:00

The issue has already shown up before, and its reason answered by John Palmer

  • 0

The issue has already shown up before, and its reason answered by John Palmer :
why is Seq.iter and Seq.map so much slower?

let ar = Array.zeroCreate<int> (64*1024*1024)
#time
//Real: 00:00:00.171, CPU: 00:00:00.171, GC gen0: 0, gen1: 0, gen2: 0
for i in 0 .. ar.Length - 1 do
    ar.[i] <- ar.[i]*3

//Real: 00:00:00.327, CPU: 00:00:00.328, GC gen0: 0, gen1: 0, gen2: 0
ar |> Array.iteri(fun i _ -> ar.[i] <- ar.[i]*3)

//Real: 00:00:02.249, CPU: 00:00:02.250, GC gen0: 0, gen1: 0, gen2: 0
ar |> Seq.iteri(fun i _ -> ar.[i] <- ar.[i]*3)

I wonder if there are some kind of “inlining” or other generic mechanisms that could map, say a Sequence to (its last known?) concrete type to accelerate those behaviour.
For instance here i have static guarantee that I will iterate over an array.

Do you know of satisfactory solution that exists in theory to this ? (what would be there fancy name ?)

Are there some langage that acknowledge and solve that issue nicely ?

  • 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-06-15T10:44:48+00:00Added an answer on June 15, 2026 at 10:44 am

    It’s true that you don’t have Higher Kinded Types in F# but still you can use inline functions and emulate some Typeclass behaviour.
    By defining a Functor you have a generic solution to native mapping:

    type Fmap = Fmap with
        static member ($) (_Functor:Fmap, x:List<_> ) = fun f -> List.map    f x  
        static member ($) (_Functor:Fmap, x:array<_>) = fun f -> Array.map   f x
        static member ($) (_Functor:Fmap, x:_ [,]   ) = fun f -> Array2D.map f x
        static member ($) (_Functor:Fmap, x:_ [,,]  ) = fun f -> Array3D.map f x
        static member ($) (_Functor:Fmap, x:_ [,,,] ) = fun f ->
            Array4D.init (x.GetLength 0) (x.GetLength 1) (x.GetLength 2) (x.GetLength 3) (fun a b c d -> f x.[a,b,c,d])
    
    let inline fmap f x = (Fmap $ x) f
    

    Take for instance fmap, this function is inline and it will accept any type defined in the overloads and it will execute as fast as calling the function directly (which is what actually happens behind the scenes).
    To iter you can use fmap and discard the result, in your case you may want to define something like fmapi to have an index available.

    Keep in mind you should call these functions always with the the concrete type, if you pass a Seq<‘a> it will fail, you should not mix both approaches: subtype and ad-hoc polymorphism.

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

Sidebar

Related Questions

This issue has been on/off bugging me and I've written 4 wrappers now. I'm
This issue has me baffled, it's affecting a single user (to my knowledge) and
I know this issue has been touched on here but I have not found
So I assume my issue has to do with what is going on under
I'm currently working on the internationalization of a product and an issue has come
Thanks for taking a look at this. The issue has to do with the
I have a batch script, I think my issue has to do with parentheses
I have a strange issue that has arisen recently: Whenever I enter text, even
so I am having this issue that has been driving me crazy for hours,
I'm working on a project, and I've come across an issue that has me

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.