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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:47:27+00:00 2026-05-13T23:47:27+00:00

I’m currently working on a Haskell project which automatically tests some functions based on

  • 0

I’m currently working on a Haskell project which automatically tests some functions based on an XML specification. The XML specification gives the arguments to each function and the expected result that the function will provide (the arguments are of many different types). I know how to extract the function arguments from the XML and parse them using the read function, but I haven’t figured out how to invoke the function using the arguments I get out.

What I basically want is to read and store the arguments in a heterogeneous list (my current thinking is to use a list of type Data.Dynamic) and then invoke the function, passing this heterogeneous list as its argument list. Is this possible? Modifying the functions under test is not an option.

  • 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-13T23:47:27+00:00Added an answer on May 13, 2026 at 11:47 pm

    I would recommend Nathan’s suggestion of using Haskell as the spec language. Haskell itself is the best possible data format for working with Haskell functions 🙂

    But since it’s an interesting question, I’ll pretend that you, by some bizarre constraint, have to use XML. You are going to have to convert your XML to a real Haskell function somewhere. That means having some mapping:

    lookupFunc :: String -> ???
    

    Which looks up a func by name. You will have to write this mapping by hand, or generate it using Template Haskell. But importantly, ??? is not a type, and this function needs a real type.

    Here’s a neat one, similar to your heterogeneous list but more optimized to the problem at hand:

    data SpecFunc = Result String | More (String -> SpecFunc)
    

    This is your interface to the XML specification. It says that either I am done and already have a result (which has already been stringified) or I need another argument to continue (with the conversion from string baked into that function). (Geeky side note: this is called the “free monad over (String ->)” — but the monadiness is quite irrelevant to us right now).

    Now we can write a typeclass to convert Haskell functions into their SpecFuncs, if their types meet our criteria:

    class HasSpecFunc a where
        toSpecFunc :: a -> SpecFunc
    
    instance (Read a, HasSpecFunc b) => HasSpecFunc (a -> b) where
        toSpecFunc f = More (\input -> toSpecFunc (f (read input)))
    
    ... -- one of these for each one of your "primitive" result types
    instance HasSpecFunc String where
        toSpecFunc x = Result (show x)
    

    Using some evil you can avoid having to specify one instance per result type. At the top of the file, enable overlapping instances:

    {-# LANGUAGE OverlappingInstances #-}
    

    Then use:

    instance (Show a) => HasSpecFunc a where
        toSpecFunc x = Result (show x)
    

    Then you can call a SpecFunc with something like:

    -- returns Nothing if the wrong number of arguments were provided
    runSpecFunc :: SpecFunc -> [String] -> Maybe String
    runSpecFunc (Result x) [] = Just x
    runSpecFunc (More f) (x:xs) = runSpecFunc (f x) xs
    runSpecFunc _ _ = Nothing
    

    I hope that made sense. But again, ditching the XML and using Haskell instead is far preferable to this.

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

Sidebar

Ask A Question

Stats

  • Questions 369k
  • Answers 369k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The best way is to use multiple JOIN clauses, one… May 14, 2026 at 6:23 pm
  • Editorial Team
    Editorial Team added an answer for example open-source projects like Vidalia or TorK, you mean?… May 14, 2026 at 6:23 pm
  • Editorial Team
    Editorial Team added an answer Ah well, now Bill basically said everything I was going… May 14, 2026 at 6:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.