Skip to content

Commit b8a52de

Browse files
brielovclaude
andcommitted
Require main function as program entry point
Programs must now define a `main : List String -> a` function as their entry point. Tail expressions are deprecated and will be ignored with a warning. - Add main function detection and signature validation in compile phase - Generate code to call main with command-line arguments (converted to List) - Remove IO.args from runtime (args now passed to main directly) - Prevent optimizer from inlining/removing main function - Update all examples to use main function instead of tail expressions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7b02191 commit b8a52de

22 files changed

Lines changed: 161 additions & 78 deletions

File tree

examples/algorithm-w/main.alg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,4 +424,4 @@ let result =
424424
t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + t11 + t12 + t13 + t14 + t15
425425

426426
-- Expected: 14 (all pass except omega which should fail occurs check)
427-
result
427+
let main = args -> IO.printLine (Int.toString result)

examples/algorithms/main.alg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,4 @@ let result =
213213
testTreeAlgorithms -- 1345689
214214
-- Total: 1482028
215215

216-
result
216+
let main = args -> IO.printLine (Int.toString result)

examples/basics/main.alg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,4 @@ let result =
311311
testIntConversion -- 177
312312
-- Total: 1233
313313

314-
result
314+
let main = args -> IO.printLine (Int.toString result)

examples/data-structures/main.alg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ let testAssoc =
155155

156156
let result = testBST + testStack + testQueue + testAssoc -- 30
157157

158-
result
158+
let main = args -> IO.printLine (Int.toString result)

examples/data-types/main.alg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,4 +426,4 @@ let result =
426426
testComplexTypes -- 44
427427
-- Total: 1151
428428

429-
result
429+
let main = args -> IO.printLine (Int.toString result)

examples/division-safety/main.alg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ let result =
5151
avg1 + avg2 -- 20 + 0 = 20
5252
-- Total: 20 + 4 + 20 = 44
5353

54-
result
54+
let main = args -> IO.printLine (Int.toString result)

examples/exhaustiveness-check/main.alg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ let result =
7575
c1 + c2 + c3 + r1 + r2 + u1 + u2 + b1 + b2 + h1 + h2 + p1 + p2
7676
-- Expected: 3 + 5 + 4 + 1 + 0 + 42 + 99 + 1 + 0 + 10 + 0 + 6 + 9 = 180
7777

78-
result
78+
let main = args -> IO.printLine (Int.toString result)

examples/functions/main.alg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,4 @@ let result =
311311
testLambdas -- 101
312312
-- Total: 1754
313313

314-
result
314+
let main = args -> IO.printLine (Int.toString result)

examples/modules/main.alg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,4 @@ let testCounter =
195195

196196
let result = testMath + testVec2 + testStack + testQueue + testCounter
197197

198-
result
198+
let main = args -> IO.printLine (Int.toString result)

examples/or-patterns/main.alg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ let result =
7070
(if startsWithZeroOrOne [5, 2, 3] then 1 else 0) -- 0
7171
-- Total: 1 + 0 + 1 + 1 + 0 + 1 + 1 + 42 + 0 + 0 + 1 + 1 + 0 + 1 + 1 + 0 = 51
7272

73-
result
73+
let main = args -> IO.printLine (Int.toString result)

0 commit comments

Comments
 (0)