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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:56:00+00:00 2026-06-11T17:56:00+00:00

I have the following haskell code to expand environment variables in strings (parsing code

  • 0

I have the following haskell code to expand environment variables in strings (parsing code omitted):

import Control.Monad (liftM)

data Token = Literal String | EnvReference String deriving Show

expandTokens :: (Monad m) => (String -> m (Maybe String)) -> [Token] -> m String
expandTokens getEnv toks = liftM concat (mapM toString toks) where
    toString (Literal s) = return s
    toString (EnvReference v) = liftM (maybe "" id) (getEnv v)

(it’s intended to be used with an IO implementation of getEnv, but I figured it would be nicer for testing if it could be used with any monad)

When I was writing it, I tried to give the nested toString function an explicit type of:

toString :: Monad m => Token -> m String

But ghc says:

Sample.hs:8:58:
    Could not deduce (m ~ m1)
    from the context (Monad m)
      bound by the type signature for
                 expandTokens :: Monad m =>
                                 (String -> m (Maybe String)) -> [Token] -> m String
( ... )

I get that the “Monad m” in the expandTokens must necessarily be the exact same m as in the type of toString (since it references the getenv of the containing function), but I can’t figure out how to write an explicit type for toString which respects that – I don’t think there’s any way to refer to anything in a different type declaration, can it even be done?

  • 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-11T17:56:01+00:00Added an answer on June 11, 2026 at 5:56 pm

    I think you’re looking for ScopedTypeVariables. I’ve never used that, but it looks right.

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

Sidebar

Related Questions

I have the following Haskell code import Data.Int import System.Environment type Coord = (Int16,
capslocker.hs has following code: import Control.Monad import Data.Char main = forever $ do putStr
I have the following Haskell code: -- Problem 69 import ProjectEuler phi :: Integer
I have the following haskell code: fac n = product [1..n] taylor3s w0 f
Let's say we have the following Haskell: data T = T0 | T1 |
I have the following Template Haskell code in my module, which is part of
I was trying to translate the following Haskell code to C++: data List t
I have written a script in haskell named testscript with the following code: #!/usr/bin/env
I have the following code: import operator def stagger(l, w): if len(l)>=w: return [tuple(l[0:w])]+stagger(l[1:],
I have a problem with a Haskell code, I have the following: takeMeHere cs

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.