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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:43:13+00:00 2026-05-13T08:43:13+00:00

A simple question I suspect. I have the simple function definition makePatientFixture :: [

  • 0

A simple question I suspect. I have the simple function definition

makePatientFixture :: [ { name :: String, age :: Int} ];
makePatientFixture = [ { name = "Dave", age = 41}, { name = "Denise", age = 45}, { name = "Cameron", age = 5} ];

I actually want to define a new type called

Patient = { name :: String, age :: Int } 

This would mean that I don’t have to repeat the record structure all of the time ({ name :: String, age :: Int }) instead my code would look like:

makePatientFixture :: [ Patient ];
makePatientFixture = [ { name = "Dave", age = 41}, { name = "Denise", age = 45}, { name = "Cameron", age = 5} ];

Is this possible? Does it make sense from a CAL perspective (it may not)?

  • 1 1 Answer
  • 1 View
  • 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-13T08:43:13+00:00Added an answer on May 13, 2026 at 8:43 am

    CAL does not support aliasing (which Haskell does with the ‘type’ keyword), so you can’t just do:

    type Patient = {name::String, age::Int}
    

    However, you can create a newdata type that incorporates your record:

    data Patient=
        public Patient
            details :: {name::String, age::Int}
        ;
    

    … however, this is probably not what you need. Records as very handy for moving around bits of structured data and using a structural polymorphism (automatic projection of record subsets). You don’t need to store the data like this though.
    Instead, I’d recommend:

    data Patient=
        public Patient
            name :: !String
            age  :: !Int
        ;
    

    The ‘plings’ on the types mean ‘don’t bother storing a lazy thunk here’, e.g. we really want a string and and int even if you apply some complicated expression to the Patient constructor. You can safely omit the plings, but it’s good practice to include them in most cases.

    You can now use various forms of case analysis to extract elements from such a Patient value. You’ll see all these in the manual, but here’s a summary:

    Overt case analysis, positional match:

    age p =
        case p of
        Patientname age -> age;  // Spot the maintenance problem here!
        ;
    

    Overt case analysis, symbol match:

    nameAndAge p =
        case p of
        Patient{name,age} -> (name,age);  // Now it doesn't matter if the Patient constructor grows new arguments
        ;
    

    Lazy extractor

    name p =
        let
            Patient{name} = p;  // name is only extracted (and p partially evaluated) if name is required
        in
            name;
    

    Single case extractor

    name p =
        p.Patient.name;  // Syntactic sugar for example 1.  Useful when you are _only_ extracting a single field. 
    

    You can always project a record from this data if you need to.
    Remember you can also have multiple constructors for the Patient data type, if there are several kinds of Patient.

    For example, perhaps there are in-patients and out-patients. Both of these share some nhs patient records, but have specific fields pertinent to their treatment.
    We could represent along the following lines:

    data Patient=
        public InPatient
            patientRecords :: !PatientRecord
            careCentreID   :: !Int
            department :: !String
            consultant :: !String
        | publicOutPatient
            patientRecords :: !PatientRecord
            appointments :: ![Appointment]
        ;
    
    
    nhsRecords p =
        case p of
        (InPatient|OutPatient) {patientRecords} -> patientRecords;
        ;
    

    This also allows us to look at a very powerful CAL feature that does multiple constructor matching. In this case we match InPatient and OutPatient, projecting only the patientRecords field.

    This allows us to write an ‘nhsRecords’ extractor function that we can maintain fairly easily even as the details in the Patient constructors change.
    Indeed, unless constructors come and go, or something happens to the “patientRecords” field itself, the this function need never change.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'd better place the bean as request (or session) attribute… May 14, 2026 at 5:35 am
  • Editorial Team
    Editorial Team added an answer Your cancel button has a target of your detail controller;… May 14, 2026 at 5:35 am
  • Editorial Team
    Editorial Team added an answer Try this, it will make the loader image appear as… May 14, 2026 at 5:35 am

Related Questions

I have a small command line utility project that I'm using Maven to manage.
I have an interesting problem. The basis of the problem is that my last
I've done a lot of reading through forum posts and tutorials, but I still
I have a simple page that returns an ajax success/error message on submission. The
Very simple problem: I have a Public Sub (in a module) that I want

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.