
You can't use guards in record syntax, but you could use `case` here instead of `let`, or just write a function of type `String -> BuyOrSell` and use that. On Sun, Apr 13, 2014 at 11:03 PM, Dimitri DeFigueiredo < defigueiredo@ucdavis.edu> wrote:
I'm having some trouble understanding where I can or cannot use guards inside record syntax. I'm writing a simple conversion routine, but I am not able to write it without inserting an extra let. Do I need a let expression here? Am I missing something?
-------------- data OldTrade = OldTrade { oldprice :: Double , oldamount :: Double , oldbuysell :: String -- "buy", "sell" or "" } deriving( Eq, Show)
data BuyOrSell = Buy | Sell | Unknown deriving(Eq, Show)
data Trade = Trade { price :: Double , amount :: Double , buysell :: BuyOrSell } deriving( Eq, Show)
convert :: OldTrade -> Trade
convert ot = Trade { price = oldprice ot, amount = oldamount ot, buysell = let x | oldbuysell ot == "buy" = Buy | oldbuysell ot == "sell" = Sell | otherwise = Unknown in x }
-- how do I eliminate the 'let' expression here? -- I wanted to write something like: -- -- buysell | oldbuysell ot == "buy" = Buy -- | oldbuysell ot == "sell" = Sell -- | otherwise = Unknown
--------------
Thanks!
Dimitri
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners