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

  • Home
  • SEARCH
  • 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 8297617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:28:48+00:00 2026-06-08T15:28:48+00:00

In Io , you can set the execution context using do : Http :=

  • 0

In Io, you can set the execution context using do:

Http := Object clone
Http get := method(uri, ("<GET request to " .. uri .. ">") println)
Http delete := method(uri, ("<DELETE request to " .. uri .. ">") println)

Database := Object clone
Database insert := method(table, data, ("<insert data to " .. table .. ">") println)
Database delete := method(table, id, ("<delete " .. id .. " from " .. table .. ">") println)

Http do(
  get("http://example.com/")
  delete("http://example.com/something")
)

Database do(
  insert("cats", list("Phil", "gray"))
  delete("cats", 12)
)

(Ruby has a similar feature with Object#instance_exec, but its object model is a bit more complicated.)

In effect, this gives you a temporary namespace, which is nice for writing domain specific languages. Is there a technique to achieve a similar effect (a temporary namespace) in Haskell?

For example, something like: (Not necessarily exactly like this, but something with similarly succinct syntax.)

main = do
  http $ do
    get "http://example.com/"
    delete "http://example.com/something"
  database $ do
    insert "cats" ["Phil", "gray"]
    delete "cats" 12

Notice that the two deletes are completely different functions. I’d prefer to avoid writing things like H.delete and D.delete, because that would get messy quick. I realize that this could be avoided by renaming that database version to, for example, deleteFrom, but I don’t want to.

  • 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-08T15:28:50+00:00Added an answer on June 8, 2026 at 3:28 pm

    “That is crazy dynamic stuff. You could never do that in a static language…”

    {-# LANGUAGE ImplicitParams, Rank2Types #-}
    import Text.Printf
    http :: (((?get :: String -> IO ()),
              (?delete :: String -> IO ())) 
             => IO a)
            -> IO a
    http a = let ?get    = \s -> printf "http get %s\n" s
                 ?delete = \s -> printf "http delete %s\n" s
             in a
    
    database :: (((?insert :: String -> [String] -> IO ()),
                  (?delete :: String -> Integer -> IO ())) 
                   => IO a) 
                -> IO a
    database a = let ?insert = \s ls -> printf "database insert %s %s\n" s (show ls)
                     ?delete = \s n  -> printf "database delete %s %d\n" s n
                 in a
    
    main = do
      http $ do
        ?get "http://example.com/"
        ?delete "http://example.com/something"
      database $ do
        ?insert "cats" ["Phil", "gray"]
        ?delete "cats" 12
    

    “that is crazy. No way it works”

    *Main> :l Crazy.hs 
    [1 of 1] Compiling Main             ( Crazy.hs, interpreted )
    Ok, modules loaded: Main.
    *Main> main
    http get http://example.com/
    http delete http://example.com/something
    database insert cats ["Phil","gray"]
    database delete cats 12
    

    you should probably not actually do things this way. But if that is really what you want, implicit parameters are probably the most elegant way to get it


    applicative’s RecordWildCard solution is in some sense better than this since it takes less code to set up, and involves a much smaller extension to the language. Furthermore it is very similar to using “open” directives in languages with proper module systems, or “using namespace” commands in languages with flexible name spacing (Haskell has neither). The implicit parameter solution captures something similar to the semantics of dynamic languages. In particular, using it you can call a function that uses the implicit arguments, and not have to worry about manually passing the environment.

    You can also simulate implicit parameters here with a ReaderT or something like it. Although (for various reasons), that is not very compositional if you want to stay in Haskell 98.

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

Sidebar

Related Questions

I can set the event on the calendar on my device by using this
I understand that we can set the various style attributes from code behind using
I know I can set a CultureInfo object with an specified culture in the
I am calling a Page Method from JQuery as described here: http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/ This is
I can set the width and height of my canvas by setting the width
I can set the relationship between View Model and view through following DataContext syntax:
You can set the Vim color scheme by issuing :colorscheme SCHEME_NAME but, oddly enough,
How can I can set a global variable for the username of the logged-in
In Photoshop you can set a layer's blending mode to be Hue. If that
In the layout you can set the EditText widget to be non-editable via the

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.