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

  • Home
  • SEARCH
  • 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 6773725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:42:07+00:00 2026-05-26T15:42:07+00:00

I have my own data type: type Types = String data MyType = MyType

  • 0

I have my own data type:

type Types = String
data MyType = MyType [Types]

I have a utility function:

initMyType :: [Types] -> MyType
initMyType types = Mytype types

Now I create:

let a = MyType ["1A", "1B", "1C"]

How can I get the list ["1A", "1B", "1C"] from a? And in general, how can I get data from a data constructor?

  • 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-26T15:42:07+00:00Added an answer on May 26, 2026 at 3:42 pm

    Besides using pattern matching, as in arrowdodger’s answer, you can also use record syntax to define the accessor automatically:

    data MyType = MyType { getList :: [Types] }
    

    This defines a type exactly the same as

    data MyType = MyType [Types]
    

    but also defines a function

    getList :: MyType -> [Types]
    

    and allows (but doesn’t require) the syntax MyType { getList = ["a", "b", "c"] } for constructing values of MyType. By the way, initMyTypes is not really necessary unless it does something else besides constructing the value, because it does exactly the same as the constructor MyType (but can’t be used in pattern matching).

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

Sidebar

Related Questions

I have create my own NSOpenGLView class, right now the data that i want
I have declared my own type: data Book = Bookinfo { bookId :: Int,
I've got an asp.net application where each client will have their own data entry
The main concept goes like this. I have four listviews with its own data
I have some data which look like that: PMID- 19587274 OWN - NLM DP
I have an own annotation processor (let's call it MyProcessor) and a project (let's
What I would like to do (in C++) is create a 'Parameter' data type
I have the following function in access, which was working fairly well. But now
I have a mapper that, while processing data, classifies output into 3 different types
In a program I'm writing, I've decided to use my own data types instead

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.