haskell: deriving (Eq, Show) for ADTs (+11 tests, 565/565)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 34s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 34s
Parser parses optional deriving clause; only appended to AST when non-empty. hk-bind-decls! data arm generates dictShow_Con / dictEq_Con per constructor. hk-binop == and /= now deep-force both sides (SX dict equality is by reference — two thunks wrapping the same value compared as not-equal without this). Three token-type fixes in the deriving parser (lparen/rparen/comma, not "special"). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -459,8 +459,9 @@
|
||||
((= op "-") (- lv rv))
|
||||
((= op "*") (* lv rv))
|
||||
((= op "/") (/ lv rv))
|
||||
((= op "==") (hk-of-bool (= lv rv)))
|
||||
((= op "/=") (hk-of-bool (not (= lv rv))))
|
||||
((= op "==") (hk-of-bool (= (hk-deep-force lv) (hk-deep-force rv))))
|
||||
((= op "/=")
|
||||
(hk-of-bool (not (= (hk-deep-force lv) (hk-deep-force rv)))))
|
||||
((= op "<") (hk-of-bool (< lv rv)))
|
||||
((= op "<=") (hk-of-bool (<= lv rv)))
|
||||
((= op ">") (hk-of-bool (> lv rv)))
|
||||
@@ -778,6 +779,67 @@
|
||||
env
|
||||
(str "dict" cls "_" (hk-type-to-runtime-key type-str))
|
||||
inst-dict))))
|
||||
((= (first d) "data")
|
||||
(let
|
||||
((deriving-list (if (> (len d) 4) (nth d 4) (list))))
|
||||
(when
|
||||
(not (empty? deriving-list))
|
||||
(let
|
||||
((cons-list (nth d 3)))
|
||||
(for-each
|
||||
(fn
|
||||
(cls)
|
||||
(for-each
|
||||
(fn
|
||||
(cdef)
|
||||
(let
|
||||
((con-name (nth cdef 1)))
|
||||
(cond
|
||||
((= cls "Show")
|
||||
(let
|
||||
((inst-dict (dict)))
|
||||
(dict-set!
|
||||
inst-dict
|
||||
"show"
|
||||
(hk-mk-lazy-builtin "show" hk-show-val 1))
|
||||
(dict-set!
|
||||
env
|
||||
(str "dictShow_" con-name)
|
||||
inst-dict)))
|
||||
((= cls "Eq")
|
||||
(let
|
||||
((inst-dict (dict)))
|
||||
(dict-set!
|
||||
inst-dict
|
||||
"=="
|
||||
(hk-mk-builtin
|
||||
"=="
|
||||
(fn
|
||||
(x y)
|
||||
(hk-of-bool
|
||||
(=
|
||||
(hk-deep-force x)
|
||||
(hk-deep-force y))))
|
||||
2))
|
||||
(dict-set!
|
||||
inst-dict
|
||||
"/="
|
||||
(hk-mk-builtin
|
||||
"/="
|
||||
(fn
|
||||
(x y)
|
||||
(hk-of-bool
|
||||
(not
|
||||
(=
|
||||
(hk-deep-force x)
|
||||
(hk-deep-force y)))))
|
||||
2))
|
||||
(dict-set!
|
||||
env
|
||||
(str "dictEq_" con-name)
|
||||
inst-dict))))))
|
||||
cons-list))
|
||||
deriving-list)))))
|
||||
(:else nil)))
|
||||
decls)
|
||||
(let
|
||||
|
||||
Reference in New Issue
Block a user