Records in Haskell

Christopher Done chrisdone at googlemail.com
Thu Sep 15 18:08:11 CEST 2011


2011/9/15 Greg Weber <greg at gregweber.info>:
> I should be clear that in my counter point I am using Ruby, not Haskell on
> those projects. In Ruby one can use a string for the name of a class (which
> will be evaluated later) and other general dynamic typing tricks to avoid
> cyclical dependencies.

Ah, okay. Sure, late binding (that's what it's called) makes it convenient.

> I have worked on one large Yesod project. I felt they were creating
> artificially shortened field names in some cases (that I found difficult to
> understand/remember) to try and ease the pain of large prefixed record
> selectors.

I can understand that. Accessors like reviewAssignSubmissionId for a
ReviewAssign record are pretty tedious but at least I don't have
trouble remembering them.

> However, Yesod does create all the records with prefixes in one
> module/file- so all the types are in there. They create a new model file for
> each model (conceptually, but not for a model representing simple embedded
> data). The model file can import all the record types.

Right, that's what I do. Types in one big types file, and then the
functions for the model in Project.Model.X which imports the types
file. This is an internal project, but it will be released as open
source in a few months so showing you the haddock output isn't a big
deal: http://chrisdone.com/confy-doc/ My militantness regarding adding
haddock docs is scant due to deadline pressures as you'd expect, but
it's not so bad.

E.g. checkout http://chrisdone.com/confy-doc/Confy-Model-Conference.html
and it's blatant I'm using a lot of other types.

All entities or entity-like things are in:
http://chrisdone.com/confy-doc/Confy-Types-Entities.html and enums in
http://chrisdone.com/confy-doc/Confy-Types-Enums.html

And do not look at
http://chrisdone.com/confy-doc/Confy-Model-Tables.html because it is
frightening and will make you go bald. If you're already bald, feel
free! HaskellDB and its HList-like record system.

> Personally I would prefer to define my type in the model file so I can
> quickly see my type with the related code if it were possible, but it seems
> that it isn't.

I guess it can be possible with a lot of discipline and patience.
Maybe others have done this in large projects and found it not so bad?



More information about the Glasgow-haskell-users mailing list