[Haskell-cafe] Haskell Data Structure design

Guru Devanla gurudev.devanla at gmail.com
Wed Jul 6 01:26:50 UTC 2016

Hello All,

I am just getting myself to code in Haskell and would like to design
advice.  Below, I have a made up example:

data ClassRoom = ClassRoom { classRoomNo:: Integer, extra_fees::Float,
students: Map StudentId Student}
data Student = Student {name::String, feesOwed::Float}
data StudentId =

get_fees_owed classroom student_id = extra_fees + feesOwed $ (students
classroom) M.! studentid

Here the `get_fees_owed`  needs information from the container

Here is my question/problem:

I believe I should model most of my code as expressions, rather than
storing pre-computed values such as `fees_owed`.  But,
defining expressions involve passing the container objects all over. For
example, deep down in a function that deals with just
one `student`, I might need the fees owed information. Without, having a
reference to the container, I cannot call get_fees_owed.

Also, I think it hinders composing of functions that just deal with one
student at a time, but end up with some dependency on
the container.

I have several questions related to this design hurdle, but I will start
with the one above.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160705/975cd6b8/attachment.html>

More information about the Haskell-Cafe mailing list