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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:42:42+00:00 2026-06-09T06:42:42+00:00

Currently I have something like this: data MyData = SomeData | MoreData | EvenMore

  • 0

Currently I have something like this:

data MyData = SomeData | MoreData | EvenMore
data DataLists = DataLists [MyData] [MyData]

Which allows me to obviously do something like this:

myDataList :: DataLists
myDataList = DataLists [SomeData, MoreData] [EvenMore, SomeData]

But I would like to instead do something like this:

-- Static Module File:

class MyClass b where
    evaluate :: b -> Int

data SomeData = SomeData
data MoreData = MoreData
data EvenMore = EvenMore

instance MyClass SomeData where
    evaluate _ = 2
instance MyClass MoreData where
    evaluate _ = 3
instance MyClass EvenMore where
    evaluate _ = 4

data DataList = DataList [MyClass] [MyClass] -- Obviously this is wrong

I would like that part of my code to remain static. Because later I would like to add in some types using that module to put in the Data List. I need this separate because the overall module will be used in 2 different projects and I don’t want to have to keep going into edit it.

data MyVeryOwnData = MyVeryOwnData
--I should be able to make up as many datastructures as I want

instance MyClass MyVeryOwnData where
   evaluate _ = 99

myList :: DataList
myList = DataList [MyVeryOwnData, SomeData] [SomeData, EvenMore]

I realize that I could simply put MyVeryOwnData in the module file like this:

data MyData = SomeData | MyVeryOwnData ...

instance MyClass MyData where
    evaluate SomeData = 2
    evaluate MoreData = 3
    ... etc.

But I dont want to do that since as I said before I want to add an arbitrary amount of datatypes in.

  • 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-09T06:42:45+00:00Added an answer on June 9, 2026 at 6:42 am

    What you’re looking for is called Heterogenous lists, and haskell supports them in mainly two ways, Existentials or GADTs. I show you a runnable code example that solved the problem with existentials.

    {-# LANGUAGE ExistentialQuantification #-}
    
    class Eval b where
        evaluate :: b -> Int
    
    data SomeData = SomeData
    data MoreData = MoreData
    data EvenMore = EvenMore
    
    instance Eval SomeData where
        evaluate _ = 2
    instance Eval MoreData where
        evaluate _ = 3
    instance Eval EvenMore where
        evaluate _ = 4
    
    data Evalable = forall a . Eval a => Evalable a
    
    instance Eval Evalable where
        evaluate (Evalable a) = evaluate a
    
    pack :: Eval a => a -> Evalable
    pack = Evalable
    
    data DataLists = DataLists [Evalable] [Evalable]
    
    getFirst :: DataLists -> [Evalable]
    getFirst (DataLists xs ys) = xs
    
    main = do
      let dl = DataLists [pack SomeData, pack EvenMore] [pack MoreData]
      print . map evaluate . getFirst $ dl
    

    It should be clear that you can add instance Eval MyVeryOwnData in outside modules, and you can then pack those values so they become Evalable and you can then put them inside your Datalists.

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

Sidebar

Related Questions

I have something like this currently: <div class = className style = position: absolute;
I currently have a table structure that looks something like this(some details omitted): ColumnName
I currently have service classes that look something like this public class UserService :
Currently, I have something like: public partial class Form1 : Form { delegate void
Currently I have a site where it has a header that looks something like
I have an app which is displaying a data set which allows me to
I have XML files containing data like this... <parent> <boy/> </parent> <parent> <girl/> <parent>
I currently have an arraylist in C# which holds the my data base table
In my Rails controller I have something like: def authenticate_user! if not current_user #
Very simple + silly question: Does clojure provide multi maps? I currently have something

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.