#1518: Make it possible to evaluate monadic actions when assigning record fields
(<-)
---------------------------------+------------------------------------------
  Reporter:  [EMAIL PROTECTED]  |          Owner:         
      Type:  feature request     |         Status:  new    
  Priority:  normal              |      Milestone:         
 Component:  Compiler            |        Version:  6.6.1  
  Severity:  normal              |       Keywords:         
Difficulty:  Unknown             |             Os:  Unknown
  Testcase:                      |   Architecture:  Unknown
---------------------------------+------------------------------------------
It is currently not possible to build records from values resulting from
 monadic actions while still using the field-specifiers.

 foo :: IO Int
 ...

 data Bar = Bar {
   barFoo :: Int
 }

 buildBar :: IO ()
 buildBar = do
   return Bar {
     barFoo <- foo --Evaluate foo to get the Int-value
   }

 I've found two possible ways of doing this:

 1) Using temporaries to evaluate the actions before assigning which
 doubles the number of lines:
 tmp <- foo
 return Bar {
   barFoo = tmp
 }

 2) Lifting the record constructor which prevents you from using field
 specifiers (and you really need field specifiers when dealing with larger
 records):
 liftM Bar foo

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1518>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to