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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:26:03+00:00 2026-06-10T11:26:03+00:00

In McBride and Paterson’s ‘Applicative programming with effects’ they introduce some lovely syntactic sugar

  • 0

In McBride and Paterson’s ‘Applicative programming with effects’ they introduce some lovely syntactic sugar for lifting a pure function:

[| f x y z |]

for

f <$> x <*> y <*> z

and I recall someone somewhere else using li f w x y z il or il f v w x y z li, and I thought/hoped that might be because it could be defined using some existing language feature and cunning definition of li and il.

I can’t find any reference to this beyond the paper, and assuming that [| and |] aren’t likely to turn up in ghc any time soon, is it possible to implement li and il somehow? I can’t think of a sensible type for them, so I assume I’d need Template Haskell or similar, but don’t know nearly enough to accomplish this. [af| f x y ] would be fine, but I don’t know whether it’s possible before I start attempting it, and certainly need help if it is.

  • 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-10T11:26:04+00:00Added an answer on June 10, 2026 at 11:26 am

    This is pretty easy to implement in Template Haskell by using the haskell-src-meta package to parse the Haskell expression in the quasi-quotation.

    {-# LANGUAGE TemplateHaskell #-}
    
    import Language.Haskell.TH
    import Language.Haskell.TH.Quote
    import Language.Haskell.Meta (parseExp)
    
    import Control.Applicative ((<*>), (<$>))
    
    af = QuasiQuoter
        { quoteExp  = parseAf
        , quotePat  = undefined
        , quoteType = undefined
        , quoteDec  = undefined
        }
    
    parseAf :: String -> Q Exp
    parseAf s = case parseExp s of
        Right ex -> applyExp ex
        Left err -> fail err
    
    applyExp :: Exp -> Q Exp
    applyExp (AppE f@(AppE _ _) a) = [|$(applyExp f) <*> $(return a)|]
    applyExp (AppE f a) = [|$(return f) <$> $(return a)|]
    applyExp _ = fail "invalid expression in af"
    

    Note that due to how Template Haskell works, you can’t use the quasiquoter from the same file where it’s defined, so save the above to its own module.

    Testing in GHCi

    *Main> :set -XTemplateHaskell
    *Main> :set -XQuasiQuotes
    *Main> [af|(+) (Just 3) (Just 8)|]
    Just 11
    *Main> [af|(+) (Just 6) Nothing|]
    Nothing
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading Conor McBride and Ross Paterson's Functional Pearl / Idioms: applicative programming with
I've been reading about applicative functors, notably in the Functional Pearl by McBride and
I was following Conor McBride's Kleisli arrows of outrageous fortune paper and I've posted
I am trying to send a JSON file to do some testing. I have
I don't know what kind of position shall I announce if the parent has
entirely in JS, no server backend. I need to allow the user to search
I have to load three arrays from a text file for homework and I
I am adding SSL to a working site. My cert is installed correctly (verified
edit 2 : Taking the hint that de Bruijn indices might be easier to
I am unable to store phone number to either an ARB or CIM profile.

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.