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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:29:38+00:00 2026-06-01T12:29:38+00:00

Supose we have a very simple model: Station has at least one Train Train

  • 0

Supose we have a very simple model:

Station has at least one Train
Train has at least two Stations

The model has to allow to check what stations any given train visits and to check what trains visit a particular station.

How to model it in Haskell?

I am a Haskell newbie, so please correct me: once an object is created, you cannot modify it – you can only make a new object based on that one (~immutability). Am I right? If so,
I’ll have to create a lot of temporary variables with semi-initialized objects (during deserialization or even in unit tests).

Basically what I need is an example of modeling domain classes in Haskell – after reading “Learn you a haskell..” I still have no idea how to use this language.

  • 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-01T12:29:39+00:00Added an answer on June 1, 2026 at 12:29 pm

    Here’s a naive approach:

    data Station = Station Train [Train]
    data Train = Train Station Station [Station]
    

    You should never have to create an uninitialized object. For example, here’s a couple sample values:

    grandCentral = Station regional [national]
    bestWestern  = Station regional [national]
    regional = Train grandCentral bestWestern []
    national = Train grandCentral bestWestern []
    

    However, there’s a lot of drawbacks to this approach; observing the in-heap cycles is impossible from within the pure subset of Haskell, so updating or using these pieces of data is tricky. The usual workaround is to model your pointers explicitly.

    type TrainMap   = Map TrainId Train
    type StationMap = Map StationId Station
    type TrainId    = Int -- use newtype for more compiler checks at
    type StationId  = Int -- the cost of more programmer annoyance
    data Train   = Train StationId StationId [StationId]
    data Station = Station TrainId [TrainId]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have downloaded and added this very simple, one file, php web file explorer
I have a very simple regex question. Suppose I have 2 conditions: url =
Sorry, a beginner's question: I have a very simple function in my Django application
Very simple question: suppose I have the following js/jquery code doSomething(); $.get(url, callback); doSomethingElse();
i have a very simple question. i searched for it everywhere but i didn't
I have question that seems very simple, but I just can't get it right.
I have a very simple viewmodel class, and a strongly typed view (which uses
Let's suppose I have a very simple Ruby program: require 'rubygems' require 'ruby-debug' x
I have a very simple html. The red div is inside the blue div
Hopefully very simple SQL question - I'm just blacking out :) I have a

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.