The closest thing to guards that'll work is multi-way-if (you'll have to put "{-# LANGUAGE MultiWayIf #-}" at the top of your source file)

e.g.

buysell = if | oldbuysell ot == "buy"  = Buy
                  | oldbuysell ot == "sell" = Sell
                  | otherwise               = Unknown

but a 'case' is slightly shorter here:


buysell = case oldbuysell ot of
   "buy"  -> Buy
   "sell" -> Sell
   _ -> Unknown


Tom


On Mon, Apr 14, 2014 at 4:22 AM, Kim-Ee Yeoh <ky3@atamo.com> wrote:

On Mon, Apr 14, 2014 at 1:03 PM, Dimitri DeFigueiredo <defigueiredo@ucdavis.edu> wrote:
    oldbuysell :: String  -- "buy", "sell" or ""

Why is this String when you've defined the perfectly cromulent BuyOrSell datatype?

How can you be sure there won't be some accidental buggy code that sets the field to "buyy"?

-- Kim-Ee

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners