@claudetools/tools 0.8.10 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/codedna/generators/astro.d.ts +18 -0
  2. package/dist/codedna/generators/astro.js +91 -0
  3. package/dist/codedna/generators/authjs.d.ts +18 -0
  4. package/dist/codedna/generators/authjs.js +68 -0
  5. package/dist/codedna/generators/better-auth.d.ts +18 -0
  6. package/dist/codedna/generators/better-auth.js +62 -0
  7. package/dist/codedna/generators/drizzle-orm.d.ts +18 -0
  8. package/dist/codedna/generators/drizzle-orm.js +65 -0
  9. package/dist/codedna/generators/elysia-api.d.ts +12 -0
  10. package/dist/codedna/generators/elysia-api.js +64 -0
  11. package/dist/codedna/generators/hono-api.d.ts +12 -0
  12. package/dist/codedna/generators/hono-api.js +64 -0
  13. package/dist/codedna/generators/lucia-auth.d.ts +18 -0
  14. package/dist/codedna/generators/lucia-auth.js +69 -0
  15. package/dist/codedna/generators/prisma.d.ts +18 -0
  16. package/dist/codedna/generators/prisma.js +64 -0
  17. package/dist/codedna/generators/react-router-v7.d.ts +18 -0
  18. package/dist/codedna/generators/react-router-v7.js +77 -0
  19. package/dist/codedna/generators/react19-shadcn.d.ts +21 -0
  20. package/dist/codedna/generators/react19-shadcn.js +367 -0
  21. package/dist/codedna/generators/sveltekit.d.ts +18 -0
  22. package/dist/codedna/generators/sveltekit.js +73 -0
  23. package/dist/codedna/generators/tanstack-start-drizzle.d.ts +92 -0
  24. package/dist/codedna/generators/tanstack-start-drizzle.js +824 -0
  25. package/dist/codedna/generators/trpc-api.d.ts +12 -0
  26. package/dist/codedna/generators/trpc-api.js +64 -0
  27. package/dist/codedna/index.d.ts +31 -0
  28. package/dist/codedna/index.js +39 -0
  29. package/dist/codedna/kappa-api-generator.d.ts +89 -0
  30. package/dist/codedna/kappa-api-generator.js +493 -0
  31. package/dist/codedna/kappa-ast.d.ts +552 -0
  32. package/dist/codedna/kappa-ast.js +141 -0
  33. package/dist/codedna/kappa-cli.d.ts +2 -0
  34. package/dist/codedna/kappa-cli.js +302 -0
  35. package/dist/codedna/kappa-component-generator.d.ts +47 -0
  36. package/dist/codedna/kappa-component-generator.js +295 -0
  37. package/dist/codedna/kappa-design-generator.d.ts +52 -0
  38. package/dist/codedna/kappa-design-generator.js +365 -0
  39. package/dist/codedna/kappa-drizzle-generator.d.ts +45 -0
  40. package/dist/codedna/kappa-drizzle-generator.js +355 -0
  41. package/dist/codedna/kappa-form-generator.d.ts +51 -0
  42. package/dist/codedna/kappa-form-generator.js +319 -0
  43. package/dist/codedna/kappa-lexer.d.ts +268 -0
  44. package/dist/codedna/kappa-lexer.js +757 -0
  45. package/dist/codedna/kappa-page-generator.d.ts +57 -0
  46. package/dist/codedna/kappa-page-generator.js +338 -0
  47. package/dist/codedna/kappa-parser.d.ts +261 -0
  48. package/dist/codedna/kappa-parser.js +2547 -0
  49. package/dist/codedna/kappa-provenance.d.ts +101 -0
  50. package/dist/codedna/kappa-provenance.js +199 -0
  51. package/dist/codedna/kappa-types-generator.d.ts +37 -0
  52. package/dist/codedna/kappa-types-generator.js +159 -0
  53. package/dist/codedna/kappa-validator.d.ts +86 -0
  54. package/dist/codedna/kappa-validator.js +638 -0
  55. package/dist/codedna/kappa-zod-generator.d.ts +32 -0
  56. package/dist/codedna/kappa-zod-generator.js +216 -0
  57. package/dist/handlers/codedna-handlers.d.ts +1 -1
  58. package/dist/handlers/kappa-handlers.d.ts +116 -0
  59. package/dist/handlers/kappa-handlers.js +465 -0
  60. package/dist/handlers/tool-handlers.js +121 -0
  61. package/dist/templates/claude-md.d.ts +1 -1
  62. package/dist/templates/claude-md.js +166 -9
  63. package/dist/tools.js +199 -0
  64. package/docs/research/2026-01-02-codedna-il-specification.md +639 -0
  65. package/docs/research/2026-01-02-codedna-v2-research.md +943 -0
  66. package/docs/research/2026-01-02-computation-foundations.md +564 -0
  67. package/docs/research/2026-01-02-hardware-description.md +814 -0
  68. package/docs/research/2026-01-02-kappa-specification.md +697 -0
  69. package/docs/research/2026-01-02-kappa-tanstack-example.md +527 -0
  70. package/docs/research/2026-01-02-kappa-v2-synthesis.md +406 -0
  71. package/docs/research/2026-01-02-kappa-v2.5-specification.md +1218 -0
  72. package/docs/research/2026-01-02-kappa-v3-specification.md +1864 -0
  73. package/docs/research/2026-01-02-kappa-whitepaper.md +662 -0
  74. package/docs/research/2026-01-02-logic-constraint.md +731 -0
  75. package/docs/research/2026-01-02-quantum-computation.md +635 -0
  76. package/package.json +4 -2
@@ -0,0 +1,814 @@
1
+ # Hardware Description Languages and Unified Computation Models
2
+
3
+ **Research Date:** 2026-01-02
4
+ **Author:** Claude (via Owen Innes)
5
+ **Purpose:** Investigate whether hardware description can be unified with software computation models
6
+
7
+ ## Executive Summary
8
+
9
+ Hardware description languages (HDLs) and software computation models **can be unified**, but doing so requires acknowledging and modeling fundamental differences in:
10
+
11
+ 1. **Concurrency Model:** Hardware is inherently concurrent (spatial parallelism), software is predominantly sequential (temporal execution)
12
+ 2. **Time Semantics:** Hardware treats time as a first-class concept; software typically abstracts it away
13
+ 3. **Physical Constraints:** Hardware must account for spatial layout, timing closure, and signal propagation delays
14
+ 4. **Evaluation Strategy:** Hardware circuits continuously evaluate; software functions evaluate on demand
15
+
16
+ **Key Finding:** Modern functional HDLs (Chisel, Clash, Lava) demonstrate that circuits CAN be expressed as functions with special effects (state, time, feedback), primarily using:
17
+ - **Monads** for state and effects
18
+ - **Arrows** for composition with feedback
19
+ - **Stream functions** for temporal behavior
20
+ - **Type systems** to enforce physical constraints (clock domains, bit widths)
21
+
22
+ However, these functional approaches still require primitives that lambda calculus alone doesn't provide: **signals**, **registers**, **timing**, and **spatial concurrency**.
23
+
24
+ ---
25
+
26
+ ## 1. Traditional HDLs: Verilog and VHDL
27
+
28
+ ### 1.1 Verilog/SystemVerilog
29
+
30
+ **Core Primitives:**
31
+ - **Modules:** Basic logic entity, analogous to functions but with concurrent semantics
32
+ - **Wires (nets):** Represent physical connections between components
33
+ - **Registers (reg/logic):** Storage elements that hold values across clock cycles
34
+ - **Gates:** Built-in primitives (AND, OR, NOT) representing physical logic gates
35
+ - **User-Defined Primitives (UDPs):** Custom gate-level components
36
+
37
+ **Key Concepts:**
38
+ - **Concurrent execution by default:** All statements in a module execute simultaneously
39
+ - **4-state logic:** Signals can be 0, 1, X (unknown), or Z (high-impedance)
40
+ - **Time as first-class:** Delay statements (#10) specify temporal behavior
41
+ - **Synthesis vs simulation:** Same code supports both abstract simulation and physical implementation
42
+
43
+ **Wire vs. Reg Evolution:**
44
+ - Originally `reg` meant sequential storage, `wire` meant combinational
45
+ - Modern SystemVerilog uses `logic` for both (4-state data type)
46
+ - **Rule of thumb:** Use `logic` for point-to-point, `wire` for multi-driver nets
47
+
48
+ **Current Standard:** IEEE 1800-2023 (merged Verilog into SystemVerilog in 2009)
49
+
50
+ **Sources:**
51
+ - [Verilog wire vs reg - Verification Horizons](https://blogs.sw.siemens.com/verificationhorizons/2013/05/03/wire-vs-reg/)
52
+ - [Verilog Wikipedia](https://en.wikipedia.org/wiki/Verilog)
53
+ - [SystemVerilog logic - Verilog Pro](https://www.verilogpro.com/verilog-reg-verilog-wire-systemverilog-logic/)
54
+
55
+ ---
56
+
57
+ ### 1.2 VHDL (VHSIC Hardware Description Language)
58
+
59
+ **Core Structural Elements:**
60
+
61
+ **Entity:**
62
+ - External interface of a hardware module
63
+ - Declares input/output port names, directions (`in`, `out`, `inout`), and types
64
+ - "Perspective of the circuit from the outside"
65
+
66
+ **Architecture:**
67
+ - Internal implementation of an entity
68
+ - Contains signals, processes, and component instantiations
69
+ - Can be behavioral, structural, or mixed
70
+
71
+ **Signals:**
72
+ - Represent wires within a circuit
73
+ - Hold current value + list of future values (event-driven simulation)
74
+ - Scope is architecture-wide (unlike variables in processes)
75
+
76
+ **Process:**
77
+ - Sequential execution block within concurrent architecture
78
+ - Key technique for behavioral modeling
79
+ - All processes execute concurrently, but statements within execute sequentially
80
+
81
+ **Modeling Styles:**
82
+ - **Dataflow:** Concurrent signal assignments (order-independent)
83
+ - **Behavioral:** Process blocks with sequential logic
84
+ - **Structural:** Component instantiation and interconnection
85
+ - **Mixed:** Combination of all three
86
+
87
+ **Origins:** Developed for US military VHSIC program (1980s)
88
+ **Current Standard:** IEEE 1076-2019
89
+
90
+ **Sources:**
91
+ - [VHDL - GeeksforGeeks](https://www.geeksforgeeks.org/electronics-engineering/vhdl-very-high-speed-integrated-circuit-hardware-description-language/)
92
+ - [VHDL Entity and Architecture - AMD Docs](https://docs.amd.com/r/en-US/ug901-vivado-synthesis/VHDL-Entity-and-Architecture-Descriptions)
93
+ - [Nandland VHDL Introduction](https://nandland.com/introduction-to-vhdl-for-beginners-with-code-examples/)
94
+
95
+ ---
96
+
97
+ ## 2. Modern Functional HDLs
98
+
99
+ ### 2.1 Chisel (Scala-based)
100
+
101
+ **Philosophy:** "Constructing Hardware in a Scala Embedded Language"
102
+
103
+ **Key Features:**
104
+ - **Embedded DSL:** Hardware primitives embedded in Scala
105
+ - **Object-oriented + functional:** Leverages Scala's type system and functional features
106
+ - **Parameterized generators:** Write circuit generators, not just circuits
107
+ - **Type-safe hardware:** Strong typing prevents many errors at compile time
108
+ - **Output:** Synthesizable Verilog via FIRRTL intermediate representation
109
+
110
+ **Why Scala?**
111
+ - Verilog/VHDL lack modern programming features (OOP, type inference, reflection)
112
+ - Scala specifically designed as base for domain-specific languages
113
+ - Provides: parameterized types, higher-order functions, type inference, pattern matching
114
+
115
+ **Architecture (Chisel3):**
116
+ - **Core:** Hardware construction primitives
117
+ - **Standard library:** Decoupled interfaces, arbiters, multiplexors
118
+ - **FIRRTL backend:** Intermediate representation for optimization and lowering
119
+
120
+ **Example Use Cases:**
121
+ - RISC-V processors (Rocket, BOOM)
122
+ - Parameterized accelerators
123
+ - Complex SoC components
124
+
125
+ **Current Status:** Active development, supported by CHIPS Alliance
126
+ **2025 Research:** LLM-based code generation (ReChisel), CGRA frontends
127
+
128
+ **Sources:**
129
+ - [Chisel GitHub](https://github.com/chipsalliance/chisel)
130
+ - [Chisel Official Site](https://www.chisel-lang.org/)
131
+ - [Chisel DAC 2012 Paper](https://aspire.eecs.berkeley.edu/chisel-archive/chisel-dac2012.pdf)
132
+
133
+ ---
134
+
135
+ ### 2.2 Clash (Haskell-based)
136
+
137
+ **Philosophy:** Functional hardware description using Haskell's full type system
138
+
139
+ **Key Features:**
140
+ - **Type-driven design:** Leverages Haskell extensions and modern type techniques
141
+ - **Separation by type:** Combinatorial and sequential logic separated in type system
142
+ - **Clock domain safety:** Incompatible clock domains separated by types (compile-time enforcement)
143
+ - **Interactive REPL:** Test components without separate testbench
144
+ - **Higher-order functions:** Fully parametric designs by default
145
+ - **Fixed-length vectors:** Type-level encoding of vector lengths
146
+ - **Multiple backends:** VHDL, Verilog, SystemVerilog
147
+
148
+ **Computational Model:**
149
+ - **Signals:** Streams of values representing wires over time
150
+ - **Synchronous sequential circuits:** Natural feedback loop descriptions
151
+ - **Type classes:** Multiple interpretations of same circuit (simulation, verification, synthesis)
152
+
153
+ **Compilation:**
154
+ 1. Haskell type checking
155
+ 2. Translation to intermediate representation
156
+ 3. Backend code generation (VHDL/Verilog/SystemVerilog)
157
+
158
+ **Project Status:**
159
+ - Open-source (BSD2 license)
160
+ - Haskell Foundation affiliated project
161
+ - Actively maintained by QBayLogic since 2009
162
+
163
+ **Sources:**
164
+ - [Clash Official Site](https://clash-lang.org/)
165
+ - [Clash GitHub](https://github.com/clash-lang/clash-compiler)
166
+ - [Clash Documentation](https://clash-lang.readthedocs.io/en/latest/general/intro.html)
167
+
168
+ ---
169
+
170
+ ### 2.3 MyHDL (Python-based)
171
+
172
+ **Philosophy:** Hardware description and verification in Python
173
+
174
+ **Core Innovation: Generators for Concurrency**
175
+
176
+ **Key Idea:** Python generators model hardware concurrency
177
+ - Generators = resumable functions
178
+ - MyHDL generators ≈ Verilog `always` blocks ≈ VHDL `process`
179
+ - Hardware module = function that returns generators
180
+
181
+ **Core Classes:**
182
+ - **Signal:** Communication between generators
183
+ - **intbv:** Bit-oriented operations
184
+ - **Enum:** Enumeration types
185
+
186
+ **Capabilities:**
187
+ - **Simulation:** Built-in simulator runs on Python interpreter
188
+ - **Waveform viewing:** VCD trace file generation
189
+ - **Conversion:** MyHDL → Verilog/VHDL
190
+ - **Verification:** Use Python unit test framework on hardware
191
+ - **Co-simulation:** Verify Verilog designs from Python
192
+
193
+ **Related Tools (2025):**
194
+ - **miniHDL:** Python DSL for learning HDL (Nicholas Carlini, 2025)
195
+ - **PyHDL/PyRTL:** Alternative Python-based HDLs
196
+ - **hdl2v:** LLM-enhanced Verilog generation (2025)
197
+
198
+ **Sources:**
199
+ - [MyHDL Official Site](https://www.myhdl.org/)
200
+ - [MyHDL Overview](https://www.myhdl.org/start/overview.html)
201
+ - [miniHDL - Nicholas Carlini](https://nicholas.carlini.com/writing/2025/minihdl-python-hardware-description-dsl.html)
202
+
203
+ ---
204
+
205
+ ### 2.4 Bluespec (Rules and Guards)
206
+
207
+ **Philosophy:** High-level synthesis based on parallel atomic transactions
208
+
209
+ **Computational Model: Guarded Atomic Actions (GAA)**
210
+
211
+ **Core Concepts:**
212
+
213
+ **Rules:**
214
+ - All behavior expressed as rewrite rules (guarded atomic actions)
215
+ - Each rule has a **guard predicate:** when it CAN execute
216
+ - Rules execute atomically when guards are true
217
+ - Compiler handles scheduling to avoid conflicts
218
+
219
+ **Guards:**
220
+ - Boolean conditions determining when operation can run
221
+ - Operations grouped into rules with conjunction of guards
222
+ - Additional rule-level guards possible
223
+ - **Fairness expectation:** Operations WILL run (not just can)
224
+
225
+ **Design Structure:**
226
+ - No process/thread model (unlike Verilog/VHDL)
227
+ - No sequential C-like model
228
+ - Everything understood as atomic rule firings
229
+ - Rules composed from fragments across module boundaries
230
+
231
+ **Theoretical Foundation:**
232
+ - Dijkstra's Guarded Commands
233
+ - UNITY, TLA+, EventB
234
+ - Long pedigree in formal specification
235
+
236
+ **Compilation:**
237
+ - Bluespec Compiler (BSC): BSV → Verilog/VHDL
238
+ - Open-source since January 2020
239
+ - Modular scheduling based on design invariants
240
+ - Ensures conflict-free rule execution
241
+ - Latest release: v2025.07
242
+
243
+ **Advantages:**
244
+ - **Modularity:** Define components by invariants
245
+ - **Automatic scheduling:** Compiler picks implementation
246
+ - **Power/performance tradeoffs:** Span various implementations
247
+ - **Formal verification:** Direct connection to formal methods
248
+
249
+ **Sources:**
250
+ - [Bluespec Grokipedia](https://grokipedia.com/page/Bluespec)
251
+ - [BSC GitHub](https://github.com/B-Lang-org/bsc)
252
+ - [Cambridge SoC Slides](https://www.cl.cam.ac.uk/teaching/1516/SysOnChip/sp4-rtl/zhp523dcb95e.html)
253
+
254
+ ---
255
+
256
+ ## 3. Can Hardware Be Unified with Software Computation?
257
+
258
+ ### 3.1 Fundamental Differences
259
+
260
+ **Concurrency:**
261
+ > "Conceptually, the distinction between hardware and software, from the perspective of computation, has only to do with the degree of concurrency and the role of time. An application with a large amount of concurrency and a heavy temporal content might as well be thought of using hardware abstractions, regardless of how it is implemented."
262
+
263
+ **Source:** [Spatial Computation - ACM SIGARCH](https://dl.acm.org/doi/10.1145/1037947.1024396)
264
+
265
+ **Time as First-Class Concept:**
266
+ - HDLs include explicit notion of time (primary attribute of hardware)
267
+ - Software programming languages typically abstract time away
268
+ - HDLs realize discrete-event model: events ordered by time stamps
269
+ - Statements execute **concurrently by default** (opposite of software)
270
+
271
+ **Spatial vs. Temporal Architectures:**
272
+
273
+ | Aspect | Temporal (CPU/GPU) | Spatial (FPGA/ASIC) |
274
+ |--------|-------------------|---------------------|
275
+ | Control | Global instruction pointer | No instruction pointer |
276
+ | Execution | Sequential through pipeline | Direct synthesis to pipelines |
277
+ | Parallelism | Time-multiplexed | Space-replicated |
278
+ | State | Centralized control | Completely distributed |
279
+
280
+ **Source:** [Spatial Hardware Performance - arXiv](https://arxiv.org/pdf/1711.07606)
281
+
282
+ ---
283
+
284
+ ### 3.2 HDL Primitives Beyond Lambda Calculus
285
+
286
+ **What lambda calculus provides:**
287
+ - Functions and application
288
+ - Variable binding
289
+ - Substitution and reduction
290
+
291
+ **What HDLs additionally need:**
292
+
293
+ 1. **Signals/Wires:**
294
+ - Physical connections with propagation delays
295
+ - Multi-driver capability (bus arbitration)
296
+ - 4-state logic (0, 1, X, Z)
297
+
298
+ 2. **Registers/State:**
299
+ - Memory across time steps
300
+ - Clock-driven updates
301
+ - Reset behavior
302
+
303
+ 3. **Timing Constraints:**
304
+ - Setup and hold times
305
+ - Clock-to-Q delays
306
+ - Critical path analysis
307
+ - Clock domain crossing
308
+
309
+ 4. **Spatial Layout:**
310
+ - Physical area constraints
311
+ - Routing between components
312
+ - Power distribution
313
+ - Signal integrity
314
+
315
+ 5. **Concurrency Control:**
316
+ - Simultaneous execution
317
+ - Event scheduling
318
+ - Race condition detection
319
+
320
+ 6. **Clock Domains:**
321
+ - Multiple independent clocks
322
+ - Synchronization mechanisms
323
+ - Metastability handling
324
+
325
+ **Sources:**
326
+ - [Hardware Description Languages - ScienceDirect](https://www.sciencedirect.com/topics/computer-science/hardware-description-languages)
327
+ - [HDL Wikipedia](https://en.wikipedia.org/wiki/Hardware_description_language)
328
+
329
+ ---
330
+
331
+ ### 3.3 Functional Approaches to Unification
332
+
333
+ **Recent breakthrough work (2025): Foundations of Digital Circuits**
334
+
335
+ **Paper:** "Foundations of Digital Circuits: Denotation, Operational, and Algebraic Semantics" (February 2025)
336
+ **Link:** [arXiv:2502.08497](https://arxiv.org/abs/2502.08497)
337
+
338
+ **Key Contribution:**
339
+ - Fully compositional theory of synchronous sequential circuits
340
+ - Applies programming language techniques to hardware
341
+ - Three semantic theories: denotational, operational, algebraic
342
+
343
+ **Denotational Semantics:**
344
+ - Sequential circuits characterized as **causal stream functions**
345
+ - Links to existing methodologies: circuit morphisms ↔ stream functions ↔ Mealy machines
346
+
347
+ **Why this matters:**
348
+ - Provides formal foundation for "circuits as functions"
349
+ - Stream functions = infinite sequences of values over time
350
+ - Causality = output at time t depends only on inputs up to time t
351
+ - Compositionality = complex circuits built from simpler ones
352
+
353
+ ---
354
+
355
+ ### 3.4 Circuits as Effectful Computations
356
+
357
+ **Key Insight:** Circuits are functions with **special effects**
358
+
359
+ **Effect Types Needed:**
360
+
361
+ 1. **State Effect (Registers):**
362
+ - Monadic state handling
363
+ - Sequential composition with memory
364
+
365
+ 2. **Time Effect (Clocks):**
366
+ - Stream-based semantics
367
+ - Synchronous dataflow
368
+
369
+ 3. **Feedback Effect (Loops):**
370
+ - Arrow notation with `rec` keyword
371
+ - ArrowLoop type class
372
+
373
+ 4. **Non-determinism (Concurrency):**
374
+ - Parallel composition
375
+ - Multiple execution paths
376
+
377
+ **Example: Linear Lambda Calculus (lλ)**
378
+
379
+ **Paper:** "A calculus for hardware description" - Park & Im
380
+ **Link:** [Cambridge Core](https://www.cambridge.org/core/journals/journal-of-functional-programming/article/calculus-for-hardware-description/E755E501B667D2B9F3F4D2F80F256464)
381
+
382
+ **Innovation:**
383
+ - **Linear type system** enforces single use of function-type variables
384
+ - Prevents resource sharing violations (physical wires can't fork without explicit split)
385
+ - Supports higher-order functions for circuit generation
386
+ - Extended with polymorphism for practical use
387
+
388
+ **Case Studies:**
389
+ - Fast Fourier Transform circuit
390
+ - Bitonic sorting network
391
+
392
+ ---
393
+
394
+ ### 3.5 Arrows for Circuit Composition
395
+
396
+ **Background:** John Hughes introduced Arrows as generalization of Monads
397
+
398
+ **Key Papers:**
399
+ - "Generalising Monads to Arrows" (Hughes, 2000)
400
+ - "Programming with Arrows" (Hughes, 2004)
401
+ - "A New Notation for Arrows" (Paterson, 2001)
402
+
403
+ **Why Arrows for Circuits?**
404
+
405
+ Monads alone don't handle **feedback loops** well:
406
+ - Simple monadic schemes fail for circuits with feedback
407
+ - Example: Flip-flops (classic feedback circuit)
408
+ - Serial adders (inputs supplied bit-by-bit, feedback for carry)
409
+
410
+ **Arrow Notation Features:**
411
+ - `proc` syntax for arrow computations
412
+ - `rec` keyword for recursive/feedback definitions
413
+ - `ArrowLoop` type class provides `loop` combinator
414
+ - Composition operators: `>>>` (sequential), `***` (parallel)
415
+
416
+ **Example Pattern:**
417
+ ```haskell
418
+ -- Serial adder with feedback
419
+ serialAdder :: Arrow a => a (Bit, Bit) Bit
420
+ serialAdder = proc (a, b) -> do
421
+ rec (sum, carry) <- addWithCarry -< (a, b, prevCarry)
422
+ prevCarry <- delay -< carry
423
+ returnA -< sum
424
+ ```
425
+
426
+ **Sources:**
427
+ - [GHC Arrow Notation](https://downloads.haskell.org/~ghc/7.8.1/docs/html/users_guide/arrow-notation.html)
428
+ - [Programming with Arrows - Hughes](https://blogs.asarkar.com/assets/docs/haskell/Programming%20with%20Arrows%20-%20Hughes.pdf)
429
+
430
+ ---
431
+
432
+ ### 3.6 Monads for Hardware Effects
433
+
434
+ **Modern Research (2025):**
435
+
436
+ **"Flexible Instruction-Set Semantics via Abstract Monads"**
437
+ **Published:** PACMPL 2025
438
+ **Link:** [ACM DL](https://dl.acm.org/doi/10.1145/3607833)
439
+
440
+ **Key Idea:**
441
+ - Parameterize semantics over **type-class instances**
442
+ - Single core semantics supports: testing, proof, model checking
443
+ - Works for **both software and hardware**
444
+ - No new language translators needed
445
+
446
+ **Benefits:**
447
+ - Pleasant prototyping of ISA semantics
448
+ - Reuse same specification for multiple purposes
449
+ - Type classes enable abstraction over monad instances
450
+
451
+ ---
452
+
453
+ **"Model-Driven Engineering from Modular Monadic Semantics"**
454
+ **Conference:** Earlier work (2000s) still relevant
455
+
456
+ **Innovation:**
457
+ - Formal system model = program in DSL defined by monad
458
+ - Monad for shared-state concurrency
459
+ - Compile to **both software and hardware**
460
+
461
+ **Workflow:**
462
+ 1. Write concurrent program in monadic DSL (Cheap Threads)
463
+ 2. Defunctionalize to abstract state machine
464
+ 3. Format in FSMLang DSL syntax
465
+ 4. FSMLang compiler produces VHDL
466
+ 5. Synthesize to FPGA
467
+
468
+ **Source:** [ResearchGate](https://www.researchgate.net/publication/221628223_Model-Driven_Engineering_from_Modular_Monadic_Semantics_Implementation_Techniques_Targeting_Hardware_and_Software)
469
+
470
+ ---
471
+
472
+ ### 3.7 Kahn Process Networks and Dataflow
473
+
474
+ **Foundational Model (1974):** Gilles Kahn introduced Kahn Process Networks (KPNs)
475
+
476
+ **Key Properties:**
477
+ - **Determinate asynchronous dataflow**
478
+ - Mathematical model: Scott-continuous functions on data streams
479
+ - Independent asynchronous sequential programs
480
+ - Communication: FIFO buffers (blocking read, non-blocking write)
481
+
482
+ **Applications:**
483
+ - Parallel programs
484
+ - Embedded systems
485
+ - Signal processing
486
+ - Stream processing
487
+ - Dataflow languages
488
+
489
+ **Modern Extensions:**
490
+
491
+ **Polychronous Model:**
492
+ - Relationship between untimed (KPN) and synchronized dataflow
493
+ - Multiple clock domains with different rates
494
+
495
+ **Network Algebra (NA):**
496
+ - Uniform algebraic framework for dataflow networks
497
+ - Three interpretations:
498
+ 1. Minimal stream delayers (synchronous dataflow)
499
+ 2. Stream delayers (asynchronous dataflow)
500
+ 3. Stream retimers (fully asynchronous)
501
+
502
+ **Sources:**
503
+ - [KPN Wikipedia](https://en.wikipedia.org/wiki/Kahn_process_networks)
504
+ - [Polychronous model - ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0167642323000400)
505
+
506
+ ---
507
+
508
+ **Recent Work (2025): A Mechanized Semantics for Dataflow Circuits**
509
+
510
+ **Authors:** Tony Law, Delphine Demange, Sandrine Blazy
511
+ **Link:** [ACM DL](https://dl.acm.org/doi/10.1145/3720432)
512
+
513
+ **Contribution:**
514
+ - Mechanized formal semantics for dataflow circuits
515
+ - Execution constrained by **data availability** (not static schedule)
516
+ - Two representations: graphs + core term calculus
517
+ - Proven semantically equivalent
518
+ - Formalized in Coq proof assistant
519
+ - Validated against Dynamatic (HLS tool for elastic circuits)
520
+
521
+ **Why this matters:**
522
+ - Proves dataflow circuits can have rigorous functional semantics
523
+ - Bridges gap between functional programming and hardware
524
+
525
+ ---
526
+
527
+ ## 4. Key Questions Answered
528
+
529
+ ### 4.1 Is hardware description fundamentally different from computation?
530
+
531
+ **Answer: No, but it emphasizes different aspects.**
532
+
533
+ Hardware description is computation with:
534
+ - **Mandatory concurrency** (everything happens simultaneously)
535
+ - **Explicit time** (clock cycles are first-class)
536
+ - **Physical constraints** (area, power, timing closure)
537
+ - **Spatial organization** (placement and routing matter)
538
+
539
+ Traditional computation abstracts these away. Modern functional HDLs show these aspects can be **captured in types and effects**.
540
+
541
+ ---
542
+
543
+ ### 4.2 Can circuits be expressed as functions with special effects?
544
+
545
+ **Answer: Yes.**
546
+
547
+ Modern research demonstrates circuits as:
548
+
549
+ 1. **Stream functions** (denotational semantics)
550
+ - Input streams → Output streams
551
+ - Causality enforced by construction
552
+
553
+ 2. **Monadic computations** (state + effects)
554
+ - State monad for registers
555
+ - Reader monad for inputs
556
+ - Writer monad for outputs
557
+
558
+ 3. **Arrow computations** (composition + feedback)
559
+ - Sequential composition: `>>>`
560
+ - Parallel composition: `***`
561
+ - Feedback loops: `rec` + `loop`
562
+
563
+ 4. **Algebraic effects** (modern approach)
564
+ - Effect handlers for custom behaviors
565
+ - Composable effect systems
566
+
567
+ **Evidence:**
568
+ - Clash compiles Haskell → VHDL/Verilog
569
+ - Lava generates FPGAs from functional descriptions
570
+ - Bluespec's atomic transactions → RTL
571
+ - Recent Coq formalization (2025) proves equivalence
572
+
573
+ ---
574
+
575
+ ### 4.3 What primitives do HDLs have that lambda calculus doesn't?
576
+
577
+ **Essential primitives:**
578
+
579
+ 1. **Signals** - Physical wires with timing
580
+ 2. **Registers** - State across time steps
581
+ 3. **Clocks** - Temporal synchronization
582
+ 4. **Delays** - Explicit time progression
583
+ 5. **Parallelism** - Simultaneous execution
584
+ 6. **Non-determinism** - Multiple drivers, race conditions
585
+
586
+ **How functional HDLs handle these:**
587
+
588
+ | Primitive | Functional Encoding |
589
+ |-----------|---------------------|
590
+ | Signals | Infinite streams (lazy evaluation) |
591
+ | Registers | State monad + stream delay |
592
+ | Clocks | Type-level tags (phantom types) |
593
+ | Delays | Stream tail operation |
594
+ | Parallelism | Parallel composition operators |
595
+ | Non-determinism | Non-deterministic choice monad |
596
+
597
+ **Source:** [Lava Hardware Design](https://www.researchgate.net/publication/2413661_Lava_Hardware_Design_in_Haskell)
598
+
599
+ ---
600
+
601
+ ### 4.4 Can timing, parallelism, and physical layout be abstracted?
602
+
603
+ **Answer: Partially, with tradeoffs.**
604
+
605
+ **Timing:**
606
+ - **High-level:** Abstract as "happens in one cycle"
607
+ - **Mid-level:** Specify clock domains (type-safe)
608
+ - **Low-level:** Cannot fully abstract critical paths
609
+ - **Tradeoff:** High-level loses timing predictability
610
+
611
+ **Parallelism:**
612
+ - **Fully abstractable** via compositional operators
613
+ - Parallel composition in Arrows: `f *** g`
614
+ - Type system ensures valid parallel structures
615
+ - Works well in functional HDLs
616
+
617
+ **Physical Layout:**
618
+ - **Mostly NOT abstractable** at HDL level
619
+ - Layout happens in synthesis/place-and-route
620
+ - HDL can give hints (constraints, attributes)
621
+ - Critical for FPGA/ASIC performance
622
+
623
+ **Clock Domain Crossing:**
624
+ - **Can be type-safe** (Clash does this)
625
+ - Different clock types prevent accidental mixing
626
+ - Synchronizers explicit in code
627
+ - Compile-time enforcement
628
+
629
+ **Synchronous vs. Asynchronous:**
630
+ - **Synchronous:** Fully abstractable (clock hides timing)
631
+ - **Asynchronous:** Must model delay explicitly
632
+ - Most modern HDLs assume synchronous
633
+
634
+ **Sources:**
635
+ - [Synchronous Design - ScienceDirect](https://www.sciencedirect.com/topics/computer-science/synchronous-design)
636
+ - [HDL Design Guidelines - Intel](https://www.intel.com/content/www/us/en/docs/programmable/683082/22-3/hdl-design-guidelines.html)
637
+
638
+ ---
639
+
640
+ ## 5. Synthesis: Toward Unified Computation
641
+
642
+ ### 5.1 The Spectrum of Abstraction
643
+
644
+ ```
645
+ Pure Lambda Calculus
646
+ ↓ + Type System
647
+ Typed Functional Languages (Haskell)
648
+ ↓ + Stream Semantics
649
+ Synchronous Dataflow (Lustre, Lucid Synchrone)
650
+ ↓ + Hardware Types (Signals, Registers)
651
+ Functional HDLs (Clash, Lava)
652
+ ↓ + Guarded Atomic Actions
653
+ High-Level HDLs (Bluespec)
654
+ ↓ + Timing Constraints
655
+ Synthesizable HDLs (Chisel, MyHDL)
656
+ ↓ + Physical Primitives
657
+ Traditional HDLs (Verilog, VHDL)
658
+ ↓ + Gate-Level Netlists
659
+ Physical Implementation
660
+ ```
661
+
662
+ **Each level adds:**
663
+ - More concrete physical constraints
664
+ - Less abstraction but more predictability
665
+ - Synthesis tools to lower to next level
666
+
667
+ ---
668
+
669
+ ### 5.2 Convergence Points
670
+
671
+ **Where hardware and software meet:**
672
+
673
+ 1. **High-Level Synthesis (HLS):**
674
+ - C/C++ → Hardware
675
+ - Abstracts timing, spatial layout
676
+ - Compiler handles optimization
677
+
678
+ 2. **Dataflow Programming:**
679
+ - Same model for SW and HW
680
+ - KPNs work on both CPUs and FPGAs
681
+
682
+ 3. **Functional Reactive Programming:**
683
+ - Event streams work in both domains
684
+ - Arrowized FRP compiles to circuits
685
+
686
+ 4. **Effect Systems:**
687
+ - Algebraic effects can model hardware
688
+ - Same abstraction for different backends
689
+
690
+ **Modern Trends (2024-2025):**
691
+ - **AI-generated HDL** (hdl2v, ReChisel)
692
+ - **Mechanized semantics** (Coq verification)
693
+ - **Type-driven design** (dependent types in Agda)
694
+ - **Elastic circuits** (dataflow with backpressure)
695
+
696
+ ---
697
+
698
+ ### 5.3 Remaining Challenges
699
+
700
+ **What's hard to abstract:**
701
+
702
+ 1. **Timing Closure:**
703
+ - Critical paths depend on physical implementation
704
+ - No purely functional abstraction
705
+ - Requires iterative refinement
706
+
707
+ 2. **Power Consumption:**
708
+ - Spatial layout affects power
709
+ - Clock gating, voltage scaling
710
+ - Not captured in functional models
711
+
712
+ 3. **Metastability:**
713
+ - Clock domain crossing hazards
714
+ - Probabilistic behavior
715
+ - Requires explicit synchronizers
716
+
717
+ 4. **Area Optimization:**
718
+ - Resource sharing vs. parallelism tradeoff
719
+ - Depends on synthesis heuristics
720
+ - Hard to predict from high-level code
721
+
722
+ 5. **Multi-Clock Systems:**
723
+ - Complex synchronization
724
+ - Type systems help but don't solve
725
+ - Still requires expertise
726
+
727
+ ---
728
+
729
+ ## 6. Conclusion
730
+
731
+ ### Can HDLs be unified with software computation models?
732
+
733
+ **Yes, with caveats:**
734
+
735
+ 1. **Theoretically:** Circuits are stream functions with effects
736
+ - Proven by formal semantics (Coq, 2025)
737
+ - Functional HDLs demonstrate in practice
738
+
739
+ 2. **Practically:** Functional HDLs bridge the gap
740
+ - Clash: Haskell → VHDL/Verilog (competitive performance)
741
+ - Chisel: Scala generators → Verilog (widely used)
742
+ - Bluespec: Rules → RTL (formal foundation)
743
+
744
+ 3. **With special primitives needed:**
745
+ - Signals (streams)
746
+ - Registers (delayed state)
747
+ - Clocks (type-level tags)
748
+ - Parallelism (compositional operators)
749
+ - Timing (cannot fully abstract)
750
+
751
+ 4. **Effect systems are key:**
752
+ - Monads for state and sequencing
753
+ - Arrows for composition and feedback
754
+ - Algebraic effects for custom behaviors
755
+ - Type systems for physical constraints
756
+
757
+ ### Lambda calculus + what = HDL?
758
+
759
+ ```
760
+ λ-calculus
761
+ + Type system (enforce correctness)
762
+ + Stream semantics (model time)
763
+ + State monad (registers)
764
+ + Arrow composition (circuits with feedback)
765
+ + Type-level clocks (domain safety)
766
+ + Synthesis backend (→ Verilog/VHDL)
767
+ = Functional HDL
768
+ ```
769
+
770
+ ### The verdict:
771
+
772
+ **Hardware description is not fundamentally different from computation.**
773
+
774
+ It's computation where:
775
+ - **Space and time are explicit**
776
+ - **Concurrency is default**
777
+ - **Physical constraints matter**
778
+
779
+ Modern functional programming provides the tools to model these aspects rigorously while maintaining compositionality and abstraction.
780
+
781
+ The unification exists. The challenge is **managing the abstraction gap** between mathematical elegance and physical reality.
782
+
783
+ ---
784
+
785
+ ## References
786
+
787
+ ### Papers
788
+ 1. Park & Im (2000). "A calculus for hardware description". Journal of Functional Programming.
789
+ 2. Law, Demange, Blazy (2025). "A Mechanized Semantics for Dataflow Circuits". PACMPL.
790
+ 3. Hughes (2000). "Generalising Monads to Arrows". Science of Computer Programming.
791
+ 4. Kahn (1974). "The semantics of a simple language for parallel programming". IFIP Congress.
792
+ 5. Bjesse et al. (1998). "Lava: Hardware Design in Haskell". ICFP.
793
+ 6. Arvind et al. (2004). "Bluespec System Verilog: efficient, correct RTL from high level specifications". MEMOCODE.
794
+
795
+ ### Tools & Languages
796
+ - **Chisel**: https://www.chisel-lang.org/
797
+ - **Clash**: https://clash-lang.org/
798
+ - **MyHDL**: https://www.myhdl.org/
799
+ - **Bluespec**: https://github.com/B-Lang-org/bsc
800
+ - **Lava**: Kansas Lava - https://ku-fpg.github.io/software/kansas-lava/
801
+
802
+ ### Standards
803
+ - **IEEE 1800-2023**: SystemVerilog
804
+ - **IEEE 1076-2019**: VHDL
805
+
806
+ ### Recent Research (2024-2025)
807
+ - arXiv:2502.08497 - Foundations of Digital Circuits
808
+ - ACM PACMPL 2025 - Flexible ISA Semantics
809
+ - ASPLOS 2025 - Parendi (Parallel RTL Simulation)
810
+
811
+ ---
812
+
813
+ **Generated:** 2026-01-02
814
+ **Task:** Research hardware description paradigm unification with software computation