haskell - Working with Scotty and Sqlite and having some trouble with the Monads -


hi pretty new haskell , have been working on small web application scotty , sqlite.

i having trouble performing sqlite operations inside scotty actions. kind of understanding 2 libraries when used in isolation.

here mvp of code

-- imports ...  routes :: scottym () routes =      post "data/:id" $         id <- param "id"         -- here confused         -- want         db <- open "store.db"         exec db "insert store (id, value) values (" <> id <> ", 'test value');" -- know there sql injection here learn parameterized queries in haskell next         close db         -- end part confused         text $ "created record " <> id <> " id."  main :: io()     scotty 3000 routes 

so can see still stuck thinking imperatively. know type of post actionm () -> scottym () , know type of close db io ()

so think need composite function goes actionm () -> io () -> scottym () not sure how write this.

is on right track?

any , advice appreciated.

monads stack (technically, monad transformers stack). means in advanced monads possible thing more basic monads further down stack.

the lift function take function 1 level down stack , "lift" current one. liftio function take generic io function , lift current context. (io, if included, bottom of monad transformer stack)

real world haskell , haskell wiki both have chapters on monad transformers.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -