Skip to content

Instantly share code, notes, and snippets.

@cmoore
Created August 13, 2009 06:05
Show Gist options
  • Save cmoore/167016 to your computer and use it in GitHub Desktop.
Save cmoore/167016 to your computer and use it in GitHub Desktop.
localSession = do
h <- oc
res <- (execStatement h "SELECT session from facebook limit 1") :: IO (Either String [[Row String]])
cc h
case res of
Right [[[(_,xx)]]] -> return xx
_ -> return "-1"
{-
How can I condense this? I can tell that I will probably need to do {} the case
statement, but I'm unclear how to get out of using do notation for the first part.
I keep trying to write something like
-}
localSession = oc >>= (\x -> execStatement x ...) >> cc h
{-
But I lose the value of the exec statement... or at least, I seem to.
Or is this the type of thing (ie. keeping a single handle open to the db and closing it
when finished) that would fit well inside a monad or somesuch?
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment