2

In acid-state tutorial all the examples use Template Haskell. However, due to some reasons I am not very keen on using it.

I know one can use acid-state without template haskell, as shown here:
http://mirror.seize.it/acid-state/examples/HelloWorldNoTH.hs

but I am wandering if there are any convenience wrappers or libraries to help make use of acid-state easier (without the use of template haskell)?

P.S.: My purpose is to implement a database layer for a web-app.

Community
  • 1
  • 1
Andriy Drozdyuk
  • 58,435
  • 50
  • 171
  • 272
  • 1
    In this case, the TH *is* the convenience wrapper you're looking for. I'm typically on the side of limiting use of Template Haskell (as are the Happstack guys afaik), but this a very safe and appropriate use of it IMO. – mightybyte Aug 03 '12 at 15:14
  • It's just there is no predefined syntax when it comes to TH - and all those `''` just look weird and hard to read (with magical uppercase variants appearing everywhere). – Andriy Drozdyuk Aug 03 '12 at 15:24
  • 1
    There is predefined syntax for this use of TH. Quasiquotes are where you don't have predefined syntax, but there are no quasiquotes here. – mightybyte Aug 04 '12 at 14:58

1 Answers1

4

You can't write a function that derives an instance for something, that's why Acid-State makes use of Template Haskell.

The developers of Acid-State have mentioned before that they wouldn't need to use TH if GHC added support for automatically deriving classes (much like data SomeData = Foo | Bar deriving (Show))

Many of the points listed against TH in the post you linked only apply under specific circumstances (for example, you can be pretty sure that Acid-State's TH functions won't launch any missiles)

I really don't think you should worry too much about using TH - it can be helpful sometimes!

tazjin
  • 673
  • 5
  • 9
  • Thanks. sorry for the dumb question but what does deriving classes do? – Andriy Drozdyuk Aug 03 '12 at 12:14
  • 1
    It adds an instance of a class automatically. In tazjin's example above, it means that you don't have to write `instance Show SomeData where showsPrec _ Foo = showString "Foo"; showsPrec _ Bar = showString "Bar"`; GHC will produce that instance automatically. It would be nice if you could also write `deriving (Acid)` or something similar. – dflemstr Aug 03 '12 at 12:31
  • Oh I see. Another dumb question: why can't this be enabled with language extensions i.e. those things in `{-# #-}` – Andriy Drozdyuk Aug 03 '12 at 15:23
  • 1
    It's possible with [Generics](http://www.haskell.org/ghc/docs/7.4.2/html/users_guide/generic-programming.html) actually, but nobody has made an adapter for `acid-state` yet as far as I know. And using Generics is slower than using TH. – dflemstr Aug 03 '12 at 16:27