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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:57:32+00:00 2026-06-09T18:57:32+00:00

When I don’t grasp how an expression in Haskell works I often find it

  • 0

When I don’t grasp how an expression in Haskell works I often find it helps to decompose it into a more basic form.

Using the following definitions

sequenceA :: (Applicative f) => [f a] -> f [a]
sequenceA [] = pure []
sequenceA (x:xs) = (:) <$> x <*> sequenceA xs

instance Applicative ((->) r) where
    pure x = (\_ -> x)
    f <*> g = \x -> f x (g x)

I rewrote sequenceA [(+3),(+2)] 3 as

(\_ -> (:)) <*> (+3) <*> ((\_ -> (:)) <*> (+2) <*> (\_-> [])) $ 3

And then turned it into (please excuse the format; I’m not sure what the convention is for splitting lines)

(\d ->(\c->(\b -> (\a -> (\_ -> (:)) a (+3) a) b (\_ -> (:)) b) c (+2) c) d (\_ -> []) d) 3

This seems right when I work through it by hand, but I can’t get GHCi to accept it. What have I done wrong here? My second question is how to convert from this form into functional composition. I’ve tried substituing dots in various combinations, but GHCi rejects all of them….

  • 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-09T18:57:34+00:00Added an answer on June 9, 2026 at 6:57 pm

    Being an idle goodfornothing, I thought I would make a computer do the expansion for me. So into GHCi, I typed

    let pu x = "(\\_ -> " ++ x ++ ")"
    let f >*< a = "(\\g -> " ++ f ++ " g (" ++ a ++ " g))"
    

    So now I have funny versions of pure and <*> which map strings which look like expressions to string which look like more complicated expressions. I then defined, similarly, the analogue of sequenceA, replacing functions by strings.

    let sqa [] = pu "[]" ; sqa (f : fs) = (pu "(:)" >*< f) >*< sqa fs
    

    I was then able to generate the expanded form of the example as follows

    putStrLn $ sqa ["(+3)","(+2)"] ++ " 3"
    

    which duly printed

    (\g -> (\g -> (\_ -> (:)) g ((+3) g)) g ((\g -> (\g -> (\_ -> (:)) g ((+2) g)) g  ((\_ -> []) g)) g)) 3
    

    This last, copied to the prompt, yielded

    [6,5]
    

    Comparing the output from my “metaprogram” with the attempt in the question shows a shorter initial prefix of lambdas, arising from a shallower nesting of <*> operations. Remember, it’s

    (pure (:) <*> (+3)) <*> ((pure (:) <*> (+2)) <*> pure [])
    

    so the outer (:) should be only three lambdas deep. I suspect the proposed expansion may correspond to a differently bracketed version of the above, perhaps

    pure (:) <*> (+3) <*> pure (:) <*> (+2) <*> pure []
    

    Indeed, when I evaluate

    putStrLn $ pu "(:)" >*< "(+3)" >*< pu "(:)" >*< "(+2)" >*< pu "[]" ++ " 3 "
    

    I get

    (\g -> (\g -> (\g -> (\g -> (\_ -> (:)) g ((+3) g)) g ((\_ -> (:)) g)) g ((+2) g)) g ((\_ -> []) g)) 3
    

    which looks like it matches the (updated)

    (\d -> (\c -> (\b -> (\a -> (\_ -> (:)) a ((+3) a)) b ((\_ -> (:)) b)) c ((+2) c)) d ((\_ -> []) d)) 3
    

    I hope this machine-assisted investigation helps to clarify what’s going on.

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

Sidebar

Related Questions

Don't know why this is happening, but after submitting a form via JS (using
Don't think that I'm mad, I understand how php works! That being said. I
Don't be frightened, its a very basic code. Just wanted to check with you
I don't know: if this works. if it's a good idea. what it is
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know a whole lot about streams. Why does the first version work using
don't know if this is possible.. I'm using sqlite3 schema: CREATE TABLE docs (id
Don't quite understand determinism in the context of concurrency and parallelism in Haskell. Some
Don't know why but I can't find a solution to this. I have 3
Don't want to sort the entries. using this does not preserve the order as

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.