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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:55:51+00:00 2026-05-27T02:55:51+00:00

In the following code, the last phrase I can put an in in front.

  • 0

In the following code, the last phrase I can put an in in front. Will it change anything?

Another question: If I decide to put in in front of the last phrase, do I need to indent it?

I tried without indenting and hugs complains

Last generator in do {…} must be an expression

import Data.Char
groupsOf _ [] = []
groupsOf n xs = 
    take n xs : groupsOf n ( tail xs )

problem_8 x = maximum . map product . groupsOf 5 $ x
main = do t <- readFile "p8.log" 
          let digits = map digitToInt $concat $ lines t
          print $ problem_8 digits

Edit

Ok, so people don’t seem to understand what I’m saying. Let me rephrase:
are the following two the same, given the context above?

1.

let digits = map digitToInt $concat $ lines t
print $ problem_8 digits

2.

let digits = map digitToInt $concat $ lines t
in print $ problem_8 digits

Another question concerning the scope of bindings declared in let: I read here that:

where Clauses.

Sometimes it is convenient to scope bindings over several guarded equations, which requires a where clause:

f x y  |  y>z           =  ...
       |  y==z          =  ...
       |  y<z           =  ...
     where z = x*x

Note that this cannot be done with a let expression, which only scopes over the expression which it encloses.

My question: so, the variable digits shouldn’t be visible to the last print phrase. Do I miss something here?

  • 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-27T02:55:51+00:00Added an answer on May 27, 2026 at 2:55 am

    Short answer: Use let without in in the body of a do-block, and in the part after the | in a list comprehension. Anywhere else, use let ... in ....


    The keyword let is used in three ways in Haskell.

    1. The first form is a let-expression.

      let variable = expression in expression
      

      This can be used wherever an expression is allowed, e.g.

      > (let x = 2 in x*2) + 3
      7
      
    2. The second is a let-statement. This form is only used inside of do-notation, and does not use in.

      do statements
         let variable = expression
         statements
      
    3. The third is similar to number 2 and is used inside of list comprehensions. Again, no in.

      > [(x, y) | x <- [1..3], let y = 2*x]
      [(1,2),(2,4),(3,6)]
      

      This form binds a variable which is in scope in subsequent generators and in the expression before the |.


    The reason for your confusion here is that expressions (of the correct type) can be used as statements within a do-block, and let .. in .. is just an expression.

    Because of the indentation rules of haskell, a line indented further than the previous one means it’s a continuation of the previous line, so this

    do let x = 42 in
         foo
    

    gets parsed as

    do (let x = 42 in foo)
    

    Without indentation, you get a parse error:

    do (let x = 42 in)
       foo
    

    In conclusion, never use in in a list comprehension or a do-block. It is unneccesary and confusing, as those constructs already have their own form of let.

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

Sidebar

Related Questions

The following code gives a segmentation fault on the last line require 'rubygems' gem
What does the last line mean in the following code? import pickle, urllib handle
I am using the following code, in the last line when I play the
In the following code, the object constructed in the last line of 'main()', seems
Executing the below code gives me the following exception on the last line: InvalidOperationException:
Hi I have a question about Batcher's odd-even-merge sort. I have the following code:
In the following code the last line doesn't work in my way: $('button.goal').click(function ()
The following code include the last number. >>> numbers = [1, 2, 3, 4,
I currently have the following code to generate a sales report over the last
i am using following code to setlistview adapter but giving me error at last

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.