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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:17:05+00:00 2026-05-23T09:17:05+00:00

Say, I want to define a record Attribute like this: data Attribute = Attribute

  • 0

Say, I want to define a record Attribute like this:

data Attribute = Attribute {name :: String, value :: Any}

This is not valid haskell code of course. But is there a type ‘Any’ which basically say any type will do? Or is to use type variable the only way?

data Attribute a = Attribute {name :: String, value :: a}

  • 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-23T09:17:05+00:00Added an answer on May 23, 2026 at 9:17 am

    Generally speaking, Any types aren’t very useful. Consider: If you make a polymorphic list that can hold anything, what can you do with the types in the list? The answer, of course, is nothing – you have no guarantee that there is any operation common to these elements.

    What one will typically do is either:

    1. Use GADTs to make a list that can contain elements of a specific typeclass, as in:

      data FooWrap where
          FooWrap :: Foo a => a -> FooWrap
      type FooList = [FooWrap]
      

      With this approach, you don’t know the concrete type of the elements, but you know they can be manipulated using elements of the Foo typeclass.

    2. Create a type to switch between specific concrete types contained in the list:

      data FooElem = ElemFoo Foo | ElemBar Bar
      type FooList = [FooElem]
      

      This can be combined with approach 1 to create a list that can hold elements that are of one of a fixed set of typeclasses.

    3. In some cases, it can be helpful to build a list of manipulation functions:

      type FooList = [Int -> IO ()]
      

      This is useful for things like event notification systems. At the time of adding an element to the list, you bind it up in a function that performs whatever manipulation you’ll later want to do.

    4. Use Data.Dynamic (not recommended!) as a cheat. However, this provides no guarantee that a specific element can be manipulated at all, and so the above approaches should be preferred.

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

Sidebar

Related Questions

Say I want to define that an URI such as: myapp://path/to/what/i/want?d=This%20is%20a%20test must be handled
Say I want the object to be something like this: var Book = {
Let's say that I have a type like this (that works): data WAE =
Lets say I want to define 2 styles. .color_red { color: Red; } .banner
Say I want to get the HTML of http://www.google.com as a String using some
Say I want to check if a record in a MySQL table exists. I'd
Say I want to have a method that takes any kind of number, is
Say in a module I want to define: a = 'a' b = 'b'
Say I am on a page at www.foo.com/foo/bar/page.jsf and want to define a navigation
Let's say that I want to define a module Pair in com.mycompany.common such that

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.