[Haskell-cafe] Are there standard idioms for lazy,
pure error handling?
Ketil Malde
ketil at malde.org
Thu Dec 3 09:35:51 EST 2009
Malcolm Wallace <malcolm.wallace at cs.york.ac.uk> writes:
> Errm, you mean: 4 `Then` 5 `Then` 1 `Then` Finally "success!"
Yes, sorry, and thanks. I guess I should learn to check with ghci
before posting... How about this for a nicer syntax?
infixr 8 :+
infixr 8 +:
data TList a e = a :+ (TList a e)
| Return e deriving Show
x +: y = x :+ (Return y)
*Main> 2 :+ 4 +: "success"
2 :+ (4 :+ Return "success")
I like the generic terminal value, it allows things like:
*Main> let count = go 0 where go i (x:xs) = x :+ go (i+1) xs; go i [] = Return i
*Main> :t count
count :: [t] -> TList t Integer
*Main> count [1..5]
1 :+ (2 :+ (3 :+ (4 :+ (5 :+ Return 5))))
(But perhaps these things can be done more elegantly using State or
similar?)
-k
--
If I haven't seen further, it is by standing in the footprints of giants
More information about the Haskell-Cafe
mailing list