Skip to content

Instantly share code, notes, and snippets.

@schovi
Created July 26, 2012 19:08
Show Gist options
  • Save schovi/3183859 to your computer and use it in GitHub Desktop.
Save schovi/3183859 to your computer and use it in GitHub Desktop.
How to use 'read' in haskell
processDbRequest :: Connection -> [String] -> String
processDbRequest conn record@(tableId:requestType:_:rawParams) =
let params = extractParams rawParams
tableId = read tableId
recordId = read (params M.! 1)
in case tableId of
1 -> "yes"
_ -> "oh no"
@schovi
Copy link
Author

schovi commented Jul 26, 2012

test.hs:7:10:
No instance for (Num String)
arising from the literal `1'
Possible fix: add an instance declaration for (Num String)
In the pattern: 1
In a case alternative: 1 -> "yes"
In the expression:
case tableId of {
1 -> "yes"
_ -> "oh no" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment