haskell how to use the previous assigned variable

advertisements
  x = do
    first <- "mfwew"
    let q = first
    a <- q
    let b = a
    putStrLn (b)
    return b

how to use the assigned variable "first" to a <- q?

thank you

I want to do something like this

    do
      b <- func a
      c <- func1 b
      func2 c

but this won't work. I know its because the IO type doesn't match, but is there other way to do it? Specifically, i want to use b again in x <- xxx b.


If I read your question and comments right than you want to just use the value of func a in func1 .. and you tried imperative do-style but then noticed that this only works for (the IO)-Monad(s).

In this case let comes quite close:

myResult a =
   let b = func a
       c = func1 b
   in func2 c

but in Haskell we usually do it with composition instead:

myResult a = func2 (func1 (func a))

which is

myResult a = func2 . func1 . func $ a

and finally you can drop the point a to get point-free-style:

myResult = func2 . func1 . func

if you like