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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:20:06+00:00 2026-05-20T18:20:06+00:00

In arrow do notation, you can use the rec keyword to write recursive definitions.

  • 0

In arrow do notation, you can use the rec keyword to write recursive definitions. So for example:

rec
    name <- function -< input
    input <- otherFunction -< name

How can this ever evaluate? It seems like it would just go into an infinite loop or something. I know it evaluates to the loop arrow combinator, but I don’t understand how that works either.

EDIT: that powers example is really helpful. How would you write that with do notation, though? I assume you would need to use rec.

  • 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-20T18:20:06+00:00Added an answer on May 20, 2026 at 6:20 pm

    This bit of magic works due to haskells laziness. As you might know, Haskell evaluates a value when needed, not when defined. Thus, this works if you don’t need the value fed in directly, or maybe later.

    rec is implemented using the loop function of ArrowLoop. It is defined as followed:

    class Arrow a => ArrowLoop a where
            loop :: a (b,d) (c,d) -> a b c
    
    instance ArrowLoop (->) where
            loop f b = let (c,d) = f (b,d) in c
    

    You can see: The output is just fed back as the input. It will be calculated just once, because Haskell will only evaluate d when it’s needed.

    Here’s an actual example of how to use the loop combinator directly. This function calculates all the powers of it’s argument:

    powers = loop $ \(x,l) -> (l,x:map(*x)l)
    

    (You could also write it like this instead: powers x = fix $ (x :) . map (*x))

    How does it works? Well, the infinite list of powers is in the l argument. The evaluation looks like this:

    powers = loop $ \(x,l) -> (l,x:map(*x)l) ==>
    powers b = let (c,d) = (\(x,l) -> (l,x:map(*x)l)) (b,d) in c ==>
    powers b = let (c,d) = (d,b:map(*b)d) in d ==> -- Now  we apply 2 as an argument
    powers 2 = let (c,d) = (d,2:map(*2)d) in d ==>
             = let (c,(2:d)) = (d,2:map(*2)d) in c ==>
             = let (c,(2:4:d)) = ((2:d),2:map(*2)(2:d)) in c ==>
             = let (c,(2:4:8:d)) = ((2:4:d),2:map(*2)(2:4:d)) in  ==> -- and so on
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you use the arrow operator with an array of type struct. For example:
I need to remove the sorting arrow from a column header. This can be
CTRL+down arrow does this, but only 1 line at a time. Is there a
How can I display a sort arrow in the header of the sorted column
What do you call this arrow looking -> operator found in PHP? It's either
How can I capture arrow keys in a terminal, without the user having to
I would like to make an arrow like so: Is this possible with just
I'm struggling with the F# type signature notation. For example let's say you have
I'm trying to use html and css to present some simple vector notation in
I want the white arrow to appear in my text input boxes so users

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.