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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:55:53+00:00 2026-05-25T22:55:53+00:00

The Learn You a Haskell tutorial has an example of using a let binder

  • 0

The Learn You a Haskell tutorial has an example of using a let binder in a list comprehension:

calcBmis xs = [bmi | (w, h) <- xs, let bmi = w / h ^ 2, bmi >= 25.0]

The function takes a list of height/weight pairs, and returns a list of the corresponding body-mass indices that exceed some limit, eg:

ghci> calcBmis [(70, 1.85), (50, 2.00), (130, 1.62)]
[49.53513183965858]

What’s interesting to me here is that the value bmi that is bound within the comprehension can be used both in a guard and in the resulting expression. The only way I know how to do something similar in Scala is to write:

def calcBmis(xs : Seq[(Double,Double)]) =
  for((w,h) <- xs ; bmi <- Some(w / (h*h)) if bmi >= 25.0) yield bmi

Having to wrap my value in a Some here feels wrong. Anyone knows of a better way?

  • 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-25T22:55:53+00:00Added an answer on May 25, 2026 at 10:55 pm

    Yes, there is such syntax.

    def calcBmis(xs : Seq[(Double,Double)]) =
      for((w,h) <- xs ; bmi = w / (h*h); if bmi >= 25.0) yield bmi
    

    One-liner alternative (but not comprehension):

    calcBmis.map(wh => wh._1/(wh._2*wh._2)).filter(_>=25.0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Learn You a Haskell has an example about functors. I can read LYAH, and
So I'm making a list of prime numbers to help me learn haskell using
I'm trying to compile this function from Learn You a Haskell for Great Good
I was reading a Haskell tutorial (Learn You a Haskell) in which the author
Working in F# has lead me to learn about Haskell. I'm currently on chapter
I'm going through the 'Learn you a Haskell' tutorial and I am at this
I am trying to write a list function that takes a simple list and
Trying to learn Haskell. I am trying to write a simple function to remove
I came across the following definition as I try to learn Haskell using a
I've been following a Learn Haskell in 10 Minutes tutorial. Everything was going well

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.