[Haskell-cafe] SML vs Haskell types
Albert Y. C. Lai
trebla at vex.net
Mon Mar 15 23:48:00 UTC 2021
You're now looking at the difference between:
-- list of booleans but the end has an Int
data T1 = End1 Int | Node1 Bool T1
whatInt1 (End1 i) = i
whatInt1 (Node1 _ xs) = whatInt1 xs
and
-- list of booleans but the end has an Int again but different
data T2 = End2 Int | FalseNode2 T2 | TrueNode2 T2
whatInt2 (End2 i) = i
-- the following two cases are unmergeable
-- but there is a mitigation if you find out about "record syntax"
whatInt2 (FalseNode2 xs) = whatInt2 xs
whatInt2 (TrueNode2 xs) = whatInt2 xs
Record syntax can mitigate it:
data T3 = End3 Int | FalseNode3 {tail3 :: T3} | TrueNode3 {tail3 :: T3}
whatInt3 (End3 i) = i
whatInt3 r = whatInt3 (tail3 r)
But I say "mitgate", not "solve", because it doesn't generalize to
data Q = QI Int
| QF {qtail :: Q} | QT {qtail :: Q}
| BF{qleft, qright :: Q} | BT{qleft, qright :: Q}
On 2021-03-12 7:59 p.m., Galaxy Being wrote:
> However, I'm still wondering how to have an abstracted (x:xs) - like
> pattern to collapse all the ingredients, i.e.,
>
> whatHolder2 (Holder2 (sh)) = sh
> whatHolder2 (shish2-head (shish2-tail)) = whatHolder2 shish2-tail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210315/1631eece/attachment.html>
More information about the Haskell-Cafe
mailing list