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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:35:08+00:00 2026-05-28T20:35:08+00:00

I have some code doing explicit recursion, and on top of that it calls

  • 0

I have some code doing explicit recursion, and on top of that it calls the same function twice when it doesn’t need to. I figure I can fix the latter, but need help with the former.

yesodIdentifier :: Text -> [LDAPEntry] -> Text
yesodIdentifier name ((LDAPEntry _ attributes):_) =
  let (Just eMail) = L.lookup "proxyAddresses" attributes
      partedEmail = L.map (S.splitOn "@") eMail -- now we have   
                                                -- [["garbage:name","domain"]]
  in yesodIdentifier' name partedEmail -- the secondary function is the problem

     where yesodIdentifier' :: Text -> [[String]] -> Text
           yesodIdentifier' nameToMatch ((name:[domain]):rest) =
             if ((unpack nameToMatch) == (sanitized name))
              then (pack (sanitized name)) `append`
                   (pack "@") `append`
                   (pack domain)
              else yesodIdentifier' nameToMatch rest
             where sanitized :: String -> String
                   sanitized dirty =
                     let (garbage:[cleanedName]) = S.splitOn ":" dirty
                     in cleanedName
           yesodIdentifier' name _ = pack "empty identifier"

What I am trying to do, is take the (String,[String]) from the LDAPEntry, and reduce it to the email address that matches the name given.

You can see where the recursion is. If I can fix this, I wouldn’t have to worry about yesodIdentifier' name _ = pack "empty identifier" as this code simply wouldn’t be called in the case that the user wasn’t in the LDAP database. I just put it there for completion.
I think this is better expressed as a fold, but I can’t quite express it correctly in my head. Any ideas?

  • 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-28T20:35:09+00:00Added an answer on May 28, 2026 at 8:35 pm

    This can be expressed as a filter. It’s not a fold since, if you do recurse, you’re recursing on rest and throwing away the earlier entries. You still have to handle the empty list:

    yesodI nameToMatch list = let result = filter (match(unpack nameToMatch)) list
                                  match s1 (s2:[domain]) = s1 == s2
                              in case result of 
                                 [] -> "empty identifier"
                                 res  -> repack (head res)
    
    repack arg@(name:[domain]) = (pack (sanitized name)) `append`
                       (pack "@") `append`
                       (pack domain)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some jquery code that is doing an ajax lookup and returning comma
I have some cross platform DNS client code that I use for doing end
I have to work with some code that isn't truly MVC (i.e., it doesn't
Currently I have some code that is doing an SFTP via expect/tcl. Its something
I have some code doing 2 times session.Get(id) on the same ISession. I can
I have some code doing this : var changes = document.getElementsByName(from); for (var c=0;
I have some code in a javascript file that needs to send queries back
I have some code that gives a user id to a utility that then
I have some C++ code that implements a basic Pixel class. Here's just a
I have some code like that: class MainApplication { protected static string _since; protected

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.