Question

I am programming a vocabulary trainer in Haskell in my spare time.

I have a file with the words where entries are modeled as algebraic data types, which look like

Word { _frq=1
     , _fra="le"  
     , _eng="the; him, her, it, them"
     , _deu="der,die,das; er,sie,es"
     , _uses=[Determiner [], Pronoun []]
     , _phrase=" vive la politique, vive l'amour"
     , _sentence="long live politics, long live love"
     , _satz="Lang lebe die Politik, lang lebe die Liebe."
     }

Most often the german translation _deu= and _satz= is most often just an empty string which I want to update within the program.

Now I have a few questions: 1. Is there a database using Haskell datatypes for haskell (I would really like type safety in my database too)? The things I found were the HDBC bindings to MySQL and the like, and some other xml/JSON stuff.

  1. If i update the file instead of using a database, is there a way around recompiling the whole program - it would be a bit tedious to do that.

and a third question

I want to save the learnt vocabularies in a datastructure which needs often to be updated, as in each learning step i update a number indicating the knowledge of this word - and sort this datastructure while inserting/or afterwards. Then i pick a new word based on its position in this datastructure. Lists seem to be inefficient for doing a full list traversal and sorting is a big effort if there is a better solution. A note at last I do have only 5000 list entries, so maybe is it worrying about speed in the wrong place?

Was it helpful?

Solution

Database-wise, take a look at Acid-State. There's also a tutorial for it as part of the Happstack Crash Course.

It does what you ask in terms of maintaining type safety in the model. I'm not sure how useful this'll be for you, but I've put it to use in a couple of web-apps, including here, and here (that second one is part of a benchmarking attempt pitting HDBC against MongoDB and AcidState, so you can use it to see how the three compare implementation-wise in the context of a Haskell web-application).

To your third question, at 5000 inserts/reads, you really shouldn't be worried about performance. If you take a look at those benchmarks I mentioned, the "large" benchmark runs a (relatively small) 50 000 transactions in very short order, and they were meatier insertions than what you seem to be doing.

OTHER TIPS

Check out Persistent from Yesod:

Persistent is Yesod’s answer to data storage- a type-safe, universal data store interface for Haskell.

[...]

Persistent allows us to choose among existing databases that are highly tuned for different data storage use cases, interoperate with other programming languages, and to use a safe and productive query interface, while still keeping the type safety of Haskell datatypes.

Persistent follows the guiding principles of type safety and concise, declarative syntax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top