Learn HardCaml in Half an Hour
inspired by fasterthanlime article on "Learn Rust in Half an Hour"
Variables and Mutability
let my_signal = Signal.of_int ~width:8 42let a = Signal.of_int ~width:4 5
let b = Signal.of_int ~width:4 3
let sum = Signal.(a +: b)Basic Operations
let a = Signal.of_int ~width:8 10
let b = Signal.of_int ~width:8 5
(* Arithmetic *)
let sum = Signal.(a +: b)
let diff = Signal.(a -: b)
let product = Signal.(a *: b)
(* Logic *)
let and_result = Signal.(a &: b)
let or_result = Signal.(a |: b)
let xor_result = Signal.(a ^: b)
(* Comparison *)
let equal = Signal.(a ==: b)
let less_than = Signal.(a <: b)Bit Manipulation
Multiplexers (the if-then-else of Hardware)
Sequential Logic (Memory!)
A More Practical Example
Modules and Interfaces
Simulation
Expect Tests and Waveforms
Always Blocks (State Machines Made Easy)
Hierarchical Design
Memory
Instantiating Verilog
Generating Verilog
Testing and Formal Verification
Types and Width Inference
Pattern Matching on Signals
Useful Libraries
Error Messages
Performance Considerations
Where to Go From Here
Last updated