[Haskell-cafe] functional database queries

Albert Y. C. Lai trebla at vex.net
Wed Feb 21 12:56:13 EST 2007


Henning Thielemann wrote:
> At
>  http://www.haskell.org/hawiki/HaskellDbTutorial
>   it is described, how database queries can be modelled with a monad.
> However, I wonder if this is also possible without monads. Say, writing
>
> "DB.map col1 $ DB.filter (\row -> col2 row == 10+2) myTable"
>
> for
>
> "SELECT col1 FROM MyTable where col2 = 10+2"

If and only if the database is a purely functional immutable data 
structure, this can be done. This is because the $ operator, function 
application, is used for control and/or dataflow.

Many interesting databases are not purely functional immutable; most 
reside in the external world and can spontaneously change behind your 
program's back. The >>= operator generalizes from function application 
to these cases. Thus the monadic way subsumes the functional way and 
covers other uses.

You can also make it an arrow. You can also make it an applicative.


More information about the Haskell-Cafe mailing list