Commit 397bbe0f97019098e7a7ef9ac135893705e95a15

Thomas de Grivel 2024-04-04T17:02:17

add type to *_init_cast

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
diff --git a/ic3/.ic3_history b/ic3/.ic3_history
index 93faa4e..3e9a609 100644
--- a/ic3/.ic3_history
+++ b/ic3/.ic3_history
@@ -1,14 +1,3 @@
-beacoup
-beaucoup
-1 / 4
-(Ratio) 1 / 4
-(Ratio) 1 / 4 * 2
-1/4 * 2
-type(1/4)
-1/4 / 13/12
-1/4 / 13/12 * 2
-(Complex) 1
-1 +i 2
 type(1 +i 2)
 1 +i 2 +i 3
 (1 +i 2) * (2 +i 3)
@@ -93,8 +82,18 @@ defmodule Plop do
   def sq = fn (x) { x + x }
 end
 Plop.sq(4)
-defmodule Plop do defoperator :operator_add :+ cfn Tag "tag_mul" (Tag, Tag, Result) 10 :left end
-defmodule Plop do def sq = fn (x) { x + x } end
-Plop.sq(4)
-defoperator :operator_add :+ cfn Tag "tag_mul" (Tag, Tag, Result) 10 :left
-
++
+%C3.Operator{
+  sym: :****,                                                                        
+  symbol_value: cfn Tag "tag_mul" (Tag, Tag, Result),
+  operator_precedence: 11,
+  operator_associativity: :left
+}
+%C3.Operator{sym: :****, symbol_value: cfn Tag "tag_mul" (Tag, Tag, Result), operator_precedence: 11}
+(Void) 0
+(Integer) 0
+(Integer) 10
+type((Integer) 10)
+type((Integer) 0)
+(Sw) 10
+(Uw) 10
diff --git a/lib/c3/0.1/c3/operator.facts b/lib/c3/0.1/c3/operator.facts
new file mode 100644
index 0000000..7f878c8
--- /dev/null
+++ b/lib/c3/0.1/c3/operator.facts
@@ -0,0 +1,4 @@
+%{module: C3.Facts.Dump,
+  version: 1}
+replace {C3.Operator, :is_a, :module}
+replace {C3.Operator, :defstruct, [sym: :+, symbol_value: ?, operator_precedence: 0, operator_associativity: :left]}
diff --git a/lib/c3/0.1/f128.facts b/lib/c3/0.1/f128.facts
new file mode 100644
index 0000000..9acc7c4
--- /dev/null
+++ b/lib/c3/0.1/f128.facts
@@ -0,0 +1,5 @@
+%{module: C3.Facts.Dump,
+  version: 1}
+replace {F128, :is_a, :module}
+replace {F128, :symbol, F128.cast}
+replace {F128.cast, :symbol_value, cfn F128 "f128_init_cast" (Result, Sym, Tag)}
diff --git a/lib/c3/0.1/f32.facts b/lib/c3/0.1/f32.facts
index 97420e9..83d2d79 100644
--- a/lib/c3/0.1/f32.facts
+++ b/lib/c3/0.1/f32.facts
@@ -2,4 +2,4 @@
   version: 1}
 replace {F32, :is_a, :module}
 replace {F32, :symbol, F32.cast}
-replace {F32.cast, :symbol_value, cfn F32 "f32_init_cast" (Result, Tag)}
+replace {F32.cast, :symbol_value, cfn F32 "f32_init_cast" (Result, Sym, Tag)}
diff --git a/lib/c3/0.1/f64.facts b/lib/c3/0.1/f64.facts
index fad6ffa..76afff9 100644
--- a/lib/c3/0.1/f64.facts
+++ b/lib/c3/0.1/f64.facts
@@ -2,4 +2,4 @@
   version: 1}
 replace {F64, :is_a, :module}
 replace {F64, :symbol, F64.cast}
-replace {F64.cast, :symbol_value, cfn F64 "f64_init_cast" (Result, Tag)}
+replace {F64.cast, :symbol_value, cfn F64 "f64_init_cast" (Result, Sym, Tag)}
diff --git a/lib/c3/0.1/integer.facts b/lib/c3/0.1/integer.facts
index 09cb5fc..3c36642 100644
--- a/lib/c3/0.1/integer.facts
+++ b/lib/c3/0.1/integer.facts
@@ -2,4 +2,4 @@
   version: 1}
 replace {Integer, :is_a, :module}
 replace {Integer, :symbol, Integer.cast}
-replace {Integer.cast, :symbol_value, cfn Integer "integer_init_cast" (Result, Tag)}
+replace {Integer.cast, :symbol_value, cfn Integer "integer_init_cast" (Result, Sym, Tag)}
diff --git a/lib/c3/0.1/str.facts b/lib/c3/0.1/str.facts
index e485096..459033c 100644
--- a/lib/c3/0.1/str.facts
+++ b/lib/c3/0.1/str.facts
@@ -2,4 +2,4 @@
   version: 1}
 replace {Str, :is_a, :module}
 replace {Str, :symbol, Str.cast}
-replace {Str.cast, :symbol_value, cfn Str "str_init_cast" (Result, Tag)}
+replace {Str.cast, :symbol_value, cfn Str "str_init_cast" (Result, Sym, Tag)}
diff --git a/lib/c3/0.1/sym.facts b/lib/c3/0.1/sym.facts
index 30ba24d..dd32895 100644
--- a/lib/c3/0.1/sym.facts
+++ b/lib/c3/0.1/sym.facts
@@ -2,4 +2,4 @@
   version: 1}
 replace {Sym, :is_a, :module}
 replace {Sym, :symbol, Sym.cast}
-replace {Sym.cast, :symbol_value, cfn Sym "sym_init_cast" (Result, Tag)}
+replace {Sym.cast, :symbol_value, cfn Sym "sym_init_cast" (Result, Sym, Tag)}
diff --git a/lib/c3/0.1/u16.facts b/lib/c3/0.1/u16.facts
index 44f6ac4..70c376a 100644
--- a/lib/c3/0.1/u16.facts
+++ b/lib/c3/0.1/u16.facts
@@ -2,4 +2,4 @@
   version: 1}
 replace {U16, :is_a, :module}
 replace {U16, :symbol, U16.cast}
-replace {U16.cast, :symbol_value, cfn U16 "u16_init_cast" (Result, Tag)}
+replace {U16.cast, :symbol_value, cfn U16 "u16_init_cast" (Result, Sym, Tag)}
diff --git a/lib/c3/0.1/u32.facts b/lib/c3/0.1/u32.facts
index c4c8f6a..4d4d606 100644
--- a/lib/c3/0.1/u32.facts
+++ b/lib/c3/0.1/u32.facts
@@ -2,4 +2,4 @@
   version: 1}
 replace {U32, :is_a, :module}
 replace {U32, :symbol, U32.cast}
-replace {U32.cast, :symbol_value, cfn U32 "u32_init_cast" (Result, Tag)}
+replace {U32.cast, :symbol_value, cfn U32 "u32_init_cast" (Result, Sym, Tag)}
diff --git a/lib/c3/0.1/u64.facts b/lib/c3/0.1/u64.facts
index 3f70362..cd5339b 100644
--- a/lib/c3/0.1/u64.facts
+++ b/lib/c3/0.1/u64.facts
@@ -2,4 +2,4 @@
   version: 1}
 replace {U64, :is_a, :module}
 replace {U64, :symbol, U64.cast}
-replace {U64.cast, :symbol_value, cfn U64 "u64_init_cast" (Result, Tag)}
+replace {U64.cast, :symbol_value, cfn U64 "u64_init_cast" (Result, Sym, Tag)}
diff --git a/lib/c3/0.1/u8.facts b/lib/c3/0.1/u8.facts
index 7393b5d..c2459e1 100644
--- a/lib/c3/0.1/u8.facts
+++ b/lib/c3/0.1/u8.facts
@@ -2,4 +2,4 @@
   version: 1}
 replace {U8, :is_a, :module}
 replace {U8, :symbol, U8.cast}
-replace {U8.cast, :symbol_value, cfn U8 "u8_init_cast" (Result, Tag)}
+replace {U8.cast, :symbol_value, cfn U8 "u8_init_cast" (Result, Sym, Tag)}
diff --git a/lib/c3/0.1/uw.facts b/lib/c3/0.1/uw.facts
index 084216e..99fe9d1 100644
--- a/lib/c3/0.1/uw.facts
+++ b/lib/c3/0.1/uw.facts
@@ -2,4 +2,4 @@
   version: 1}
 replace {Uw, :is_a, :module}
 replace {Uw, :symbol, Uw.cast}
-replace {Uw.cast, :symbol_value, cfn Uw "uw_init_cast" (Result, Tag)}
+replace {Uw.cast, :symbol_value, cfn Uw "uw_init_cast" (Result, Sym, Tag)}
diff --git a/lib/c3/0.1/void.facts b/lib/c3/0.1/void.facts
index 39d5dfc..5243ce3 100644
--- a/lib/c3/0.1/void.facts
+++ b/lib/c3/0.1/void.facts
@@ -2,4 +2,4 @@
   version: 1}
 replace {Void, :is_a, :module}
 replace {Void, :symbol, Void.cast}
-replace {Void.cast, :symbol_value, cfn Void "void_init_cast" (Result, Tag)}
+replace {Void.cast, :symbol_value, cfn Void "void_init_cast" (Result, Sym, Tag)}
diff --git a/libc3/array.c b/libc3/array.c
index 6615a33..1d8a362 100644
--- a/libc3/array.c
+++ b/libc3/array.c
@@ -241,8 +241,12 @@ s_array * array_init_1 (s_array *array, const char *p)
   return array;
 }
 
-s_array * array_init_cast (s_array *array, const s_tag *tag)
+s_array * array_init_cast (s_array *array, const s_sym *type, const s_tag *tag)
 {
+  assert(array);
+  assert(type);
+  assert(tag);
+  (void) type;
   switch (tag->type) {
   case TAG_ARRAY:
     return array_init_copy(array, &tag->data.array);
diff --git a/libc3/array.h b/libc3/array.h
index fd20b0d..2f53517 100644
--- a/libc3/array.h
+++ b/libc3/array.h
@@ -20,7 +20,8 @@ void      array_clean (s_array *a);
 s_array * array_init (s_array *a, const s_sym *array_type,
                       uw dimension, const uw *dimensions);
 s_array * array_init_1 (s_array *a, const char *p);
-s_array * array_init_cast (s_array *a, const s_tag *tag);
+s_array * array_init_cast (s_array *a, const s_sym *type,
+                           const s_tag *tag);
 s_array * array_init_copy (s_array *a, const s_array *src);
 s_array * array_init_copy_shallow (s_array *a, const s_array *src);
 s_array * array_init_void (s_array *array);
diff --git a/libc3/bool.c b/libc3/bool.c
index f4c07b4..f2bb8a6 100644
--- a/libc3/bool.c
+++ b/libc3/bool.c
@@ -18,11 +18,13 @@
 #include "integer.h"
 #include "io.h"
 #include "ratio.h"
+#include "sym.h"
 #include "tag_type.h"
 
-bool * bool_init_cast (bool *b, const s_tag *tag)
+bool * bool_init_cast (bool *b, const s_sym *type, const s_tag *tag)
 {
   assert(b);
+  assert(type);
   assert(tag);
   switch (tag->type) {
   case TAG_BOOL:      *b = tag->data.bool;                     return b;
@@ -45,8 +47,9 @@ bool * bool_init_cast (bool *b, const s_tag *tag)
   case TAG_U32:       *b = tag->data.u32 != 0;                 return b;
   case TAG_U64:       *b = tag->data.u64 != 0;                 return b;
   case TAG_UW:        *b = tag->data.uw != 0;                  return b;
-  case TAG_PTAG:      return tag->data.ptag ?
-      bool_init_cast(b, tag->data.ptag) : (*b = false, b);
+  case TAG_PTAG:
+    return tag->data.ptag ?
+      bool_init_cast(b, type, tag->data.ptag) : (*b = false, b);
   case TAG_PTR:       *b = tag->data.ptr.p != 0;               return b;
   case TAG_PTR_FREE:  *b = tag->data.ptr_free.p != 0;          return b;
   case TAG_ARRAY:
@@ -71,7 +74,13 @@ bool * bool_init_cast (bool *b, const s_tag *tag)
   }
   err_write_1("bool_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to Bool");
+  if (type == &g_sym_Bool)
+    err_puts(" to Bool");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka Bool");
+  }
   assert(! "bool_cast: cannot cast to Bool");
   return NULL;
 }
diff --git a/libc3/bool.h b/libc3/bool.h
index 4daf91b..0c36b85 100644
--- a/libc3/bool.h
+++ b/libc3/bool.h
@@ -22,7 +22,7 @@
 #include "types.h"
 
 /* Stack-allocation compatible functions */
-bool * bool_init_cast (bool *b, const s_tag *tag);
+bool * bool_init_cast (bool *b, const s_sym *type, const s_tag *tag);
 bool * bool_init_copy (bool *b, const bool *src);
 
 /* Observers */
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index e4629ea..5b9f80d 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -748,7 +748,8 @@ sw buf_inspect_cast (s_buf *buf, const s_call *call)
   assert(buf);
   assert(call);
   assert(call->arguments);
-  assert(! list_next(call->arguments));
+  assert(list_next(call->arguments));
+  assert(! list_next(list_next(call->arguments)));
   module = call->ident.module;
   if ((r = buf_inspect_paren_sym(buf, module)) < 0)
     return r;
@@ -756,7 +757,7 @@ sw buf_inspect_cast (s_buf *buf, const s_call *call)
   if ((r = buf_write_1(buf, " ")) < 0)
     return r;
   result += r;
-  arg = &call->arguments->tag;
+  arg = &list_next(call->arguments)->tag;
   if ((r = buf_inspect_tag(buf, arg)) < 0)
     return r;
   result += r;
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 143ae19..330b154 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -980,9 +980,11 @@ sw buf_parse_cast (s_buf *buf, s_call *dest)
   if ((r = buf_ignore_spaces(buf)) < 0)
     goto restore;
   result += r;
-  call_init_op_unary(&tmp);
+  call_init_op(&tmp);
   ident_init(&tmp.ident, module, &g_sym_cast);
-  if ((r = buf_parse_tag_primary(buf, &tmp.arguments->tag)) <= 0)
+  tag_init_sym(&tmp.arguments->tag, module);
+  if ((r = buf_parse_tag_primary(buf,
+                                 &list_next(tmp.arguments)->tag)) <= 0)
     goto clean;
   result += r;
   *dest = tmp;
diff --git a/libc3/c3.c b/libc3/c3.c
index 97b4f46..b37b71e 100644
--- a/libc3/c3.c
+++ b/libc3/c3.c
@@ -112,7 +112,7 @@ s_tag * c3_if_then_else (const s_tag *cond, const s_tag *then,
   s_tag tmp;
   if (! env_eval_tag(&g_c3_env, cond, &tmp))
     return NULL;
-  if (! bool_init_cast(&b, &tmp)) {
+  if (! bool_init_cast(&b, &g_sym_Bool, &tmp)) {
     tag_clean(&tmp);
     return NULL;
   }
diff --git a/libc3/call.c b/libc3/call.c
index a7cd4bb..9b25dfc 100644
--- a/libc3/call.c
+++ b/libc3/call.c
@@ -199,18 +199,29 @@ s_call * call_init_1 (s_call *call, const char *p)
 
 s_call * call_init_call_cast (s_call *call, const s_sym *type)
 {
+  s_list *next;
   s_call tmp = {0};
   tmp.ident.module = type;
   tmp.ident.sym = &g_sym_cast;
-  tmp.arguments = list_new(NULL);
-  if (! tmp.arguments)
+  next = list_new(NULL);
+  if (! next)
+    return NULL;
+  tmp.arguments = list_new(next);
+  if (! tmp.arguments) {
+    list_delete_all(next);
     return NULL;
+  }
+  tag_init_sym(&tmp.arguments->tag, type);
   *call = tmp;
   return call;
 }
 
-s_call * call_init_cast (s_call *call, const s_tag *tag)
+s_call * call_init_cast (s_call *call, const s_sym *type,
+                         const s_tag *tag)
 {
+  assert(call);
+  assert(type);
+  assert(tag);
   switch (tag->type) {
   case TAG_CALL:
     return call_init_copy(call, &tag->data.call);
@@ -219,7 +230,13 @@ s_call * call_init_cast (s_call *call, const s_tag *tag)
   }
   err_write_1("call_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to Call");
+  if (type == &g_sym_Call)
+    err_puts(" to Call");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka Call");
+  }
   assert(! "call_init_cast: cannot cast to Call");
   return NULL;
 }
diff --git a/libc3/call.h b/libc3/call.h
index 13044d9..c6f1a39 100644
--- a/libc3/call.h
+++ b/libc3/call.h
@@ -20,7 +20,8 @@ void     call_clean (s_call *call);
 s_call * call_init (s_call *call);
 s_call * call_init_1 (s_call *call, const char *p);
 s_call * call_init_call_cast (s_call *call, const s_sym *type);
-s_call * call_init_cast (s_call *call, const s_tag *tag);
+s_call * call_init_cast (s_call *call, const s_sym *type,
+                         const s_tag *tag);
 s_call * call_init_copy (s_call *call, const s_call *src);
 s_call * call_init_op (s_call *call);
 s_call * call_init_op_unary (s_call *call);
diff --git a/libc3/cfn.c b/libc3/cfn.c
index 107e67a..fe94888 100644
--- a/libc3/cfn.c
+++ b/libc3/cfn.c
@@ -179,8 +179,9 @@ s_cfn * cfn_init (s_cfn *cfn, const s_sym *name, s_list *arg_types,
   return cfn;
 }
 
-s_cfn * cfn_init_cast (s_cfn *cfn, const s_tag *tag)
+s_cfn * cfn_init_cast (s_cfn *cfn, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_CFN:
     return cfn_init_copy(cfn, &tag->data.cfn);
diff --git a/libc3/cfn.h b/libc3/cfn.h
index 3b1da26..8b81fb0 100644
--- a/libc3/cfn.h
+++ b/libc3/cfn.h
@@ -19,7 +19,7 @@
 void    cfn_clean (s_cfn *cfn);
 s_cfn * cfn_init (s_cfn *cfn, const s_sym *name, s_list *arg_types,
                   const s_sym *result_type);
-s_cfn * cfn_init_cast (s_cfn *cfn, const s_tag *tag);
+s_cfn * cfn_init_cast (s_cfn *cfn, const s_sym *type, const s_tag *tag);
 s_cfn * cfn_init_copy (s_cfn *cfn, const s_cfn *src);
 
 /* Heap-allocation functions, call cfn_delete after use. */
diff --git a/libc3/character.c b/libc3/character.c
index 959efc5..73e1641 100644
--- a/libc3/character.c
+++ b/libc3/character.c
@@ -14,6 +14,7 @@
 #include "character.h"
 #include "integer.h"
 #include "str.h"
+#include "sym.h"
 #include "tag_type.h"
 #include "ucd.h"
 
@@ -27,9 +28,11 @@ character character_1 (const char *p)
   return c;
 }
 
-character * character_init_cast (character *c, const s_tag *tag)
+character * character_init_cast (character *c, const s_sym *type,
+                                 const s_tag *tag)
 {
   assert(c);
+  assert(type);
   assert(tag);
   switch (tag->type) {
   case TAG_CHARACTER: *c = tag->data.character;                return c;
@@ -50,7 +53,13 @@ character * character_init_cast (character *c, const s_tag *tag)
   }
   err_write_1("character_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to Character");
+  if (type == &g_sym_Character)
+    err_puts(" to Character");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka Character");
+  }
   assert(! "character_cast: cannot cast to Character");
   return NULL;
 }
diff --git a/libc3/character.h b/libc3/character.h
index a22fbd2..d244579 100644
--- a/libc3/character.h
+++ b/libc3/character.h
@@ -18,7 +18,8 @@
 
 character   character_1 (const char *p);
 void        character_hash_update (character c, t_hash *hash);
-character * character_init_cast (character *c, const s_tag *tag);
+character * character_init_cast (character *c, const s_sym *type,
+                                 const s_tag *tag);
 character * character_init_copy (character *c, const character *src);
 bool        character_is_digit (character c);
 bool        character_is_lowercase (character c);
diff --git a/libc3/complex.c b/libc3/complex.c
index 9555196..7db55d2 100644
--- a/libc3/complex.c
+++ b/libc3/complex.c
@@ -16,6 +16,8 @@
 #include "complex.h"
 #include "f32.h"
 #include "f64.h"
+#include "f128.h"
+#include "sym.h"
 #include "tag.h"
 #include "tag_init.h"
 
@@ -338,7 +340,7 @@ f32 complex_to_f32 (const s_complex *c)
   f32 x;
   assert(c);
   complex_norm(c, &norm);
-  f32_init_cast(&x, &norm);
+  f32_init_cast(&x, &g_sym_F32, &norm);
   return x;
 }
 
@@ -348,6 +350,16 @@ f64 complex_to_f64 (const s_complex *c)
   f64 x;
   assert(c);
   complex_norm(c, &norm);
-  f64_init_cast(&x, &norm);
+  f64_init_cast(&x, &g_sym_F64, &norm);
+  return x;
+}
+
+f128 complex_to_f128 (const s_complex *c)
+{
+  s_tag norm;
+  f128 x;
+  assert(c);
+  complex_norm(c, &norm);
+  f128_init_cast(&x, &g_sym_F128, &norm);
   return x;
 }
diff --git a/libc3/complex.h b/libc3/complex.h
index 425a8a4..6ca25e2 100644
--- a/libc3/complex.h
+++ b/libc3/complex.h
@@ -65,5 +65,6 @@ s_complex * complex_new_copy (const s_complex *a);
 bool complex_is_zero (const s_complex *c);
 f32  complex_to_f32 (const s_complex *c);
 f64  complex_to_f64 (const s_complex *c);
+f128 complex_to_f128 (const s_complex *c);
 
 #endif /* LIBC3_COMPLEX_H */
diff --git a/libc3/data.c b/libc3/data.c
index 5eb35db..3bdb75d 100644
--- a/libc3/data.c
+++ b/libc3/data.c
@@ -474,70 +474,68 @@ bool data_hash_update (const s_sym *type, t_hash *hash, const void *data)
   return false;
 }
 
-void * data_init_cast (const s_sym *type, void *data, const s_tag *tag)
+void * data_init_cast (void *data, const s_sym *type, const s_tag *tag)
 {
   const s_struct_type *st;
   if (type == &g_sym_Array ||
       sym_is_array_type(type))
-    return array_init_cast(data, tag);
+    return array_init_cast(data, type, tag);
   if (type == &g_sym_Bool)
-    return bool_init_cast(data, tag);
+    return bool_init_cast(data, type, tag);
   if (type == &g_sym_Call)
-    return call_init_cast(data, tag);
+    return call_init_cast(data, type, tag);
   if (type == &g_sym_Cfn)
-    return cfn_init_cast(data, tag);
+    return cfn_init_cast(data, type, tag);
   if (type == &g_sym_Character)
-    return character_init_cast(data, tag);
+    return character_init_cast(data, type, tag);
   if (type == &g_sym_F32)
-    return f32_init_cast(data, tag);
+    return f32_init_cast(data, type, tag);
   if (type == &g_sym_F64)
-    return f64_init_cast(data, tag);
+    return f64_init_cast(data, type, tag);
   if (type == &g_sym_Fact)
-    return fact_init_cast(data, tag);
+    return fact_init_cast(data, type, tag);
   if (type == &g_sym_Fn)
-    return fn_init_cast(data, tag);
+    return fn_init_cast(data, type, tag);
   if (type == &g_sym_Ident)
-    return ident_init_cast(data, tag);
+    return ident_init_cast(data, type, tag);
   if (type == &g_sym_Integer)
-    return integer_init_cast(data, tag);
+    return integer_init_cast(data, type, tag);
   if (type == &g_sym_List)
-    return list_init_cast(data, tag);
+    return list_init_cast(data, type, tag);
   if (type == &g_sym_Ptag)
-    return ptag_init_cast(data, tag);
+    return ptag_init_cast(data, type, tag);
   if (type == &g_sym_Ptr)
-    return ptr_init_cast(data, tag);
+    return ptr_init_cast(data, type, tag);
   if (type == &g_sym_PtrFree)
-    return ptr_free_init_cast(data, tag);
+    return ptr_free_init_cast(data, type, tag);
   if (type == &g_sym_Quote)
-    return quote_init_cast(data, tag);
+    return quote_init_cast(data, type, tag);
   if (type == &g_sym_S8)
-    return s8_init_cast(data, tag);
+    return s8_init_cast(data, type, tag);
   if (type == &g_sym_S16)
-    return s16_init_cast(data, tag);
+    return s16_init_cast(data, type, tag);
   if (type == &g_sym_S32)
-    return s32_init_cast(data, tag);
+    return s32_init_cast(data, type, tag);
   if (type == &g_sym_S64)
-    return s64_init_cast(data, tag);
+    return s64_init_cast(data, type, tag);
   if (type == &g_sym_Str)
-    return str_init_cast(data, tag);
-  if (type == &g_sym_Struct)
-    return struct_init_cast(data, tag);
+    return str_init_cast(data, type, tag);
   if (type == &g_sym_Sw)
-    return sw_init_cast(data, tag);
+    return sw_init_cast(data, type, tag);
   if (type == &g_sym_Sym)
-    return sym_init_cast(data, tag);
+    return sym_init_cast(data, type, tag);
   if (type == &g_sym_Tuple)
-    return tuple_init_cast(data, tag);
+    return tuple_init_cast(data, type, tag);
   if (type == &g_sym_U8)
-    return u8_init_cast(data, tag);
+    return u8_init_cast(data, type, tag);
   if (type == &g_sym_U16)
-    return u16_init_cast(data, tag);
+    return u16_init_cast(data, type, tag);
   if (type == &g_sym_U32)
-    return u32_init_cast(data, tag);
+    return u32_init_cast(data, type, tag);
   if (type == &g_sym_U64)
-    return u64_init_cast(data, tag);
+    return u64_init_cast(data, type, tag);
   if (type == &g_sym_Uw)
-    return uw_init_cast(data, tag);
+    return uw_init_cast(data, type, tag);
   if (type == &g_sym_Var)
     return data;
   if (type == &g_sym_Void)
@@ -550,7 +548,7 @@ void * data_init_cast (const s_sym *type, void *data, const s_tag *tag)
     s_struct s = {0};
     s.type = st;
     s.data = data;
-    return struct_init_cast(&s, tag);
+    return struct_init_cast(&s, type, tag);
   }
   err_write_1("data_init_cast: unknown type: ");
   err_inspect_sym(&type);
diff --git a/libc3/data.h b/libc3/data.h
index 55b98ce..dbc3177 100644
--- a/libc3/data.h
+++ b/libc3/data.h
@@ -27,7 +27,7 @@ bool   data_clean (const s_sym *type, void *v);
 bool   data_compare (const s_sym *type, const void *a, const void *b);
 bool   data_hash_update (const s_sym *type, t_hash *hash,
                          const void *s);
-void * data_init_cast (const s_sym *type, void *v, const s_tag *src);
+void * data_init_cast (void *v, const s_sym *type, const s_tag *src);
 void * data_init_copy (const s_sym *type, void *v, const void *src);
 
 #endif /* LIBC3_DATA_H */
diff --git a/libc3/env.c b/libc3/env.c
index 7d57dba..e56c29d 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -262,7 +262,7 @@ bool env_eval_array (s_env *env, const s_array *array, s_array *dest)
       while (i < tmp.count) {
         if (! env_eval_tag(env, tag, &tag_eval))
           goto ko;
-        if (! data_init_cast(tmp.element_type, data, &tag_eval)) {
+        if (! data_init_cast(data, tmp.element_type, &tag_eval)) {
           err_write_1("env_eval_array: cannot cast ");
           err_inspect_tag(&tag_eval);
           err_write_1(" to ");
@@ -1266,8 +1266,8 @@ bool env_eval_struct (s_env *env, const s_struct *s, s_tag *dest)
     if (s->tag) {
       if (! env_eval_tag(env, s->tag + i, &tag))
         goto ko;
-      if (! data_init_cast(type, (s8 *) t->data + t->type->offset[i],
-                           &tag)) {
+      if (! data_init_cast((s8 *) t->data + t->type->offset[i],
+                           type, &tag)) {
         err_write_1("env_eval_struct: invalid type ");
         err_write_1(tag_type_to_string(tag.type));
         err_write_1(" for key ");
diff --git a/libc3/f128.c b/libc3/f128.c
index 6ec1c0d..5bce202 100644
--- a/libc3/f128.c
+++ b/libc3/f128.c
@@ -12,16 +12,19 @@
  */
 #include <stdlib.h>
 #include "assert.h"
+#include "f128.h"
 #include "integer.h"
+#include "ratio.h"
+#include "sym.h"
 #include "tag.h"
 #include "tag_type.h"
-#include "f128.h"
 #include "u64.h"
 
-f128 * f128_init_cast (f128 *x, const s_tag *tag)
+f128 * f128_init_cast (f128 *x, const s_sym *type, const s_tag *tag)
 {
-  assert(tag);
   assert(x);
+  assert(type);
+  assert(tag);
   switch (tag->type) {
   case TAG_BOOL:
     *x = tag->data.bool ? 1.0 : 0.0;
@@ -41,6 +44,9 @@ f128 * f128_init_cast (f128 *x, const s_tag *tag)
   case TAG_INTEGER:
     *x = integer_to_f128(&tag->data.integer);
     return x;
+  case TAG_RATIO:
+    *x = ratio_to_f128(&tag->data.ratio);
+    return x;
   case TAG_SW:
     *x = (f128) tag->data.sw;
     return x;
@@ -76,7 +82,13 @@ f128 * f128_init_cast (f128 *x, const s_tag *tag)
   }
   err_write_1("f128_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to F128");
+  if (type == &g_sym_F128)
+    err_puts(" to F128");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka F128");
+  }
   assert(! "f128_init_cast: cannot cast to F128");
   return NULL;
 }
diff --git a/libc3/f128.h b/libc3/f128.h
index aa9b317..261744d 100644
--- a/libc3/f128.h
+++ b/libc3/f128.h
@@ -15,7 +15,7 @@
 
 #include "types.h"
 
-f128 * f128_init_cast (f128 *x, const s_tag *tag);
+f128 * f128_init_cast (f128 *x, const s_sym *type, const s_tag *tag);
 f128 * f128_init_copy (f128 *x, const f128 *src);
 f128 * f128_random (f128 *x);
 
diff --git a/libc3/f32.c b/libc3/f32.c
index a0bf135..3dc20aa 100644
--- a/libc3/f32.c
+++ b/libc3/f32.c
@@ -12,15 +12,19 @@
  */
 #include <stdlib.h>
 #include "assert.h"
+#include "f32.h"
 #include "integer.h"
+#include "ratio.h"
+#include "sym.h"
 #include "tag.h"
 #include "tag_type.h"
-#include "ratio.h"
-#include "f32.h"
 #include "u32.h"
 
-f32 * f32_init_cast (f32 *x, const s_tag *tag)
+f32 * f32_init_cast (f32 *x, const s_sym *type, const s_tag *tag)
 {
+  assert(x);
+  assert(type);
+  assert(tag);
   switch (tag->type) {
   case TAG_BOOL:
     *x = tag->data.bool ? 1.0f : 0.0f;
@@ -75,7 +79,13 @@ f32 * f32_init_cast (f32 *x, const s_tag *tag)
   }
   err_write_1("f32_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to F32");
+  if (type == &g_sym_F32)
+    err_puts(" to F32");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka F32");
+  }
   assert(! "f32_init_cast: cannot cast to F32");
   return NULL;
 }
diff --git a/libc3/f32.h b/libc3/f32.h
index d41eb7a..db5345a 100644
--- a/libc3/f32.h
+++ b/libc3/f32.h
@@ -15,7 +15,7 @@
 
 #include "types.h"
 
-f32 * f32_init_cast (f32 *x, const s_tag *tag);
+f32 * f32_init_cast (f32 *x, const s_sym *type, const s_tag *tag);
 f32 * f32_init_copy (f32 *x, const f32 *src);
 f32 * f32_random (f32 *x);
 
diff --git a/libc3/f64.c b/libc3/f64.c
index 085caf0..4457968 100644
--- a/libc3/f64.c
+++ b/libc3/f64.c
@@ -12,17 +12,19 @@
  */
 #include <stdlib.h>
 #include "assert.h"
+#include "f64.h"
 #include "integer.h"
+#include "ratio.h"
+#include "sym.h"
 #include "tag.h"
 #include "tag_type.h"
-#include "ratio.h"
-#include "f64.h"
 #include "u64.h"
 
-f64 * f64_init_cast (f64 *x, const s_tag *tag)
+f64 * f64_init_cast (f64 *x, const s_sym *type, const s_tag *tag)
 {
-  assert(tag);
   assert(x);
+  assert(type);
+  assert(tag);
   switch (tag->type) {
   case TAG_BOOL:
     *x = tag->data.bool ? 1.0 : 0.0;
@@ -74,7 +76,13 @@ f64 * f64_init_cast (f64 *x, const s_tag *tag)
   }
   err_write_1("f64_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to F64");
+  if (type == &g_sym_F64)
+    err_puts(" to F64");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka F64");
+  }
   assert(! "f64_init_cast: cannot cast to F64");
   return NULL;
 }
diff --git a/libc3/f64.h b/libc3/f64.h
index 5a509be..c233ce0 100644
--- a/libc3/f64.h
+++ b/libc3/f64.h
@@ -15,7 +15,7 @@
 
 #include "types.h"
 
-f64 * f64_init_cast (f64 *x, const s_tag *tag);
+f64 * f64_init_cast (f64 *x, const s_sym *type, const s_tag *tag);
 f64 * f64_init_copy (f64 *x, const f64 *src);
 f64 * f64_random (f64 *x);
 
diff --git a/libc3/fact.c b/libc3/fact.c
index 9dddeb7..2c61e69 100644
--- a/libc3/fact.c
+++ b/libc3/fact.c
@@ -15,6 +15,7 @@
 #include "buf_inspect.h"
 #include "hash.h"
 #include "fact.h"
+#include "sym.h"
 #include "tag.h"
 
 uw fact_hash_uw (const s_fact *fact)
@@ -37,8 +38,12 @@ s_fact * fact_init (s_fact *fact, const s_tag *subject,
   return fact;
 }
 
-s_fact * fact_init_cast (s_fact *fact, const s_tag *tag)
+s_fact * fact_init_cast (s_fact *fact, const s_sym *type,
+                         const s_tag *tag)
 {
+  assert(fact);
+  assert(type);
+  assert(tag);
   switch (tag->type) {
   case TAG_FACT:
     return fact_init_copy(fact, &tag->data.fact);
@@ -47,7 +52,13 @@ s_fact * fact_init_cast (s_fact *fact, const s_tag *tag)
   }
   err_write_1("fact_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to Fact");
+  if (type == &g_sym_Fact)
+    err_puts(" to Fact");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka Fact");
+  }
   assert(! "fact_init_cast: cannot cast to Fact");
   return NULL;
 }
diff --git a/libc3/fact.h b/libc3/fact.h
index f0fd778..d92af14 100644
--- a/libc3/fact.h
+++ b/libc3/fact.h
@@ -19,7 +19,8 @@
 #define  fact_clean(fact) do {} while(0)
 s_fact * fact_init (s_fact *fact, const s_tag *subject,
                     const s_tag *predicate, const s_tag *object);
-s_fact * fact_init_cast (s_fact *fact, const s_tag *tag);
+s_fact * fact_init_cast (s_fact *fact, const s_sym *type,
+                         const s_tag *tag);
 s_fact * fact_init_copy (s_fact *fact, const s_fact *src);
 
 /* Observers */
diff --git a/libc3/fn.c b/libc3/fn.c
index b528c8e..e2efcf7 100644
--- a/libc3/fn.c
+++ b/libc3/fn.c
@@ -20,6 +20,7 @@
 #include "fn.h"
 #include "fn_clause.h"
 #include "list.h"
+#include "sym.h"
 #include "tag_type.h"
 
 s8 fn_arity (const s_fn *fn)
@@ -79,8 +80,11 @@ s_fn * fn_init_1 (s_fn *fn, char *p)
   return fn;
 }
 
-s_fn * fn_init_cast (s_fn *fn, const s_tag *tag)
+s_fn * fn_init_cast (s_fn *fn, const s_sym *type, const s_tag *tag)
 {
+  assert(fn);
+  assert(type);
+  assert(tag);
   switch (tag->type) {
   case TAG_FN:
     return fn_init_copy(fn, &tag->data.fn);
@@ -89,7 +93,13 @@ s_fn * fn_init_cast (s_fn *fn, const s_tag *tag)
   }
   err_write_1("fn_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to Fn");
+  if (type == &g_sym_Fn)
+    err_puts(" to Fn");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka Fn");
+  }
   assert(! "fn_init_cast: cannot cast to Fn");
   return NULL;
 }
diff --git a/libc3/fn.h b/libc3/fn.h
index 4f678e8..b76e111 100644
--- a/libc3/fn.h
+++ b/libc3/fn.h
@@ -25,7 +25,7 @@
 void   fn_clean (s_fn *fn);
 s_fn * fn_init (s_fn *fn);
 s_fn * fn_init_1 (s_fn *fn, char *p);
-s_fn * fn_init_cast (s_fn *fn, const s_tag *tag);
+s_fn * fn_init_cast (s_fn *fn, const s_sym *type, const s_tag *tag);
 s_fn * fn_init_copy (s_fn *fn, const s_fn *src);
 
 /* Heap-allocation functions, call fn_delete after use. */
diff --git a/libc3/ident.h b/libc3/ident.h
index 0c5b9cb..cd1d38f 100644
--- a/libc3/ident.h
+++ b/libc3/ident.h
@@ -23,7 +23,8 @@
 s_ident * ident_init (s_ident *ident, const s_sym *module,
                       const s_sym *sym);
 s_ident * ident_init_1 (s_ident *ident, const char *p);
-s_ident * ident_init_cast (s_ident *ident, const s_tag *tag);
+s_ident * ident_init_cast (s_ident *ident, const s_sym *type,
+                           const s_tag *tag);
 s_ident * ident_init_copy (s_ident *ident, const s_ident *src);
 
 /* Modifiers */
diff --git a/libc3/integer.c b/libc3/integer.c
index 6ebe061..ad9bdd9 100644
--- a/libc3/integer.c
+++ b/libc3/integer.c
@@ -134,8 +134,10 @@ uw integer_bytes (const s_integer *i)
   return (integer_bits(i) + 7) / 8;
 }
 
-s_integer * integer_init_cast (s_integer *a, const s_tag *tag)
+s_integer * integer_init_cast (s_integer *a, const s_sym *type,
+                               const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     return integer_init_u8(a, tag->data.bool ? 1 : 0);
diff --git a/libc3/integer.h b/libc3/integer.h
index 0513618..ab2bcd9 100644
--- a/libc3/integer.h
+++ b/libc3/integer.h
@@ -26,7 +26,8 @@
 /* Stack allocation compatible functions */
 s_integer * integer_init (s_integer *i);
 s_integer * integer_init_1 (s_integer *i, const char *p);
-s_integer * integer_init_cast (s_integer *a, const s_tag *tag);
+s_integer * integer_init_cast (s_integer *a, const s_sym *type,
+                               const s_tag *tag);
 s_integer * integer_init_copy (s_integer *a, const s_integer *src);
 s_integer * integer_init_f32 (s_integer *a, f32 x);
 s_integer * integer_init_f64 (s_integer *a, f64 x);
diff --git a/libc3/list.c b/libc3/list.c
index 1110f51..5ecbef8 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -74,8 +74,12 @@ s_list * list_init_1 (s_list *list, const char *p, s_list *next)
   return list;
 }
 
-s_list ** list_init_cast (s_list **list, const s_tag *tag)
+s_list ** list_init_cast (s_list **list, const s_sym *type,
+                          const s_tag *tag)
 {
+  assert(list);
+  assert(type);
+  assert(tag);
   switch (tag->type) {
   case TAG_LIST:
     return list_init_copy(list,
@@ -85,7 +89,13 @@ s_list ** list_init_cast (s_list **list, const s_tag *tag)
   }
   err_write_1("list_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to List");
+  if (type == &g_sym_List)
+    err_puts(" to List");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka List");
+  }
   assert(! "list_init_cast: cannot cast to List");
   return NULL;
 }
diff --git a/libc3/list.h b/libc3/list.h
index 225d987..d01c361 100644
--- a/libc3/list.h
+++ b/libc3/list.h
@@ -28,7 +28,8 @@
 void      list_clean (s_list *list);
 s_list  * list_init (s_list *list, s_list *next);
 s_list  * list_init_1 (s_list *list, const char *p, s_list *next);
-s_list ** list_init_cast (s_list **list, const s_tag *tag);
+s_list ** list_init_cast (s_list **list, const s_sym *type,
+                          const s_tag *tag);
 s_list ** list_init_copy (s_list **list, const s_list * const *src);
 s_list  * list_init_copy_tag (s_list *list, const s_tag *tag,
                               s_list *next);
diff --git a/libc3/ptag.c b/libc3/ptag.c
index 39c0091..a2cef3e 100644
--- a/libc3/ptag.c
+++ b/libc3/ptag.c
@@ -12,10 +12,15 @@
  */
 #include "assert.h"
 #include "ptag.h"
+#include "sym.h"
 #include "tag_type.h"
 
-p_tag * ptag_init_cast (p_tag *ptag, const s_tag *tag)
+p_tag * ptag_init_cast (p_tag *ptag, const s_sym *type,
+                        const s_tag *tag)
 {
+  assert(ptag);
+  assert(type);
+  assert(tag);
   switch (tag->type) {
   case TAG_PTAG:
     return ptag_init_copy(ptag, &tag->data.ptag);
@@ -24,7 +29,13 @@ p_tag * ptag_init_cast (p_tag *ptag, const s_tag *tag)
   }
   err_write_1("ptag_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to Ptag");
+  if (type == &g_sym_Ptag)
+    err_puts(" to Ptag");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka Ptag");
+  }
   assert(! "ptag_init_cast: cannot cast to Ptag");
   return NULL;
 }
diff --git a/libc3/ptag.h b/libc3/ptag.h
index 865d87c..b35cb74 100644
--- a/libc3/ptag.h
+++ b/libc3/ptag.h
@@ -15,7 +15,8 @@
 
 #include "types.h"
 
-p_tag * ptag_init_cast (p_tag *dest, const s_tag *tag);
+p_tag * ptag_init_cast (p_tag *dest, const s_sym *type,
+                        const s_tag *tag);
 p_tag * ptag_init_copy (p_tag *dest, const p_tag *src);
 
 #endif /* LIBC3_PTAG_H */
diff --git a/libc3/ptr.c b/libc3/ptr.c
index 8321198..9bccfdb 100644
--- a/libc3/ptr.c
+++ b/libc3/ptr.c
@@ -14,6 +14,7 @@
 #include "assert.h"
 #include "integer.h"
 #include "ptr.h"
+#include "sym.h"
 #include "tag_type.h"
 
 void ptr_delete (u_ptr_w *ptr)
@@ -31,10 +32,12 @@ u_ptr_w * ptr_init (u_ptr_w *ptr, void *p)
   return ptr;
 }
 
-u_ptr_w * ptr_init_cast (u_ptr_w *p, const s_tag *tag)
+u_ptr_w * ptr_init_cast (u_ptr_w *p, const s_sym *type,
+                         const s_tag *tag)
 {
-  assert(tag);
   assert(p);
+  assert(type);
+  assert(tag);
   switch (tag->type) {
   case TAG_F32: p->p = (void *) ((uw) tag->data.f32);  return p;
   case TAG_F64: p->p = (void *) ((uw) tag->data.f64);  return p;
@@ -57,7 +60,13 @@ u_ptr_w * ptr_init_cast (u_ptr_w *p, const s_tag *tag)
   }
   err_write_1("ptr_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to Ptr");
+  if (type == &g_sym_Ptr)
+    err_puts(" to Ptr");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka Ptr");
+  }
   assert(! "ptr_cast: cannot cast to Ptr");
   return NULL;
 }
diff --git a/libc3/ptr.h b/libc3/ptr.h
index 5d97aea..26ff8e0 100644
--- a/libc3/ptr.h
+++ b/libc3/ptr.h
@@ -17,7 +17,8 @@
 
 /* Stack-allocation compatible functions. */
 u_ptr_w * ptr_init (u_ptr_w *ptr, void *p);
-u_ptr_w * ptr_init_cast (u_ptr_w *ptr, const s_tag *tag);
+u_ptr_w * ptr_init_cast (u_ptr_w *ptr, const s_sym *type,
+                         const s_tag *tag);
 u_ptr_w * ptr_init_copy (u_ptr_w *ptr, const u_ptr_w *src);
 
 /* Heap-allocation functions, call ptr_delete after use. */
diff --git a/libc3/ptr_free.c b/libc3/ptr_free.c
index 06f8e0c..19fdabd 100644
--- a/libc3/ptr_free.c
+++ b/libc3/ptr_free.c
@@ -14,6 +14,7 @@
 #include "assert.h"
 #include "integer.h"
 #include "ptr_free.h"
+#include "sym.h"
 #include "tag_type.h"
 
 void ptr_free_clean (u_ptr_w *ptr_free)
@@ -38,10 +39,12 @@ u_ptr_w * ptr_free_init (u_ptr_w *ptr_free, void *p)
   return ptr_free;
 }
 
-u_ptr_w * ptr_free_init_cast (u_ptr_w *p, const s_tag *tag)
+u_ptr_w * ptr_free_init_cast (u_ptr_w *p, const s_sym *type,
+                              const s_tag *tag)
 {
-  assert(tag);
   assert(p);
+  assert(type);
+  assert(tag);
   switch (tag->type) {
   case TAG_F32: p->p = (void *) ((uw) tag->data.f32);  return p;
   case TAG_F64: p->p = (void *) ((uw) tag->data.f64);  return p;
@@ -63,7 +66,13 @@ u_ptr_w * ptr_free_init_cast (u_ptr_w *p, const s_tag *tag)
   }
   err_write_1("ptr_free_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to PtrFree");
+  if (type == &g_sym_PtrFree)
+    err_puts(" to PtrFree");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka PtrFree");
+  }
   assert(! "ptr_free_init_cast: cannot cast to PtrFree");
   return NULL;
 }
diff --git a/libc3/ptr_free.h b/libc3/ptr_free.h
index 633e417..4123e25 100644
--- a/libc3/ptr_free.h
+++ b/libc3/ptr_free.h
@@ -19,7 +19,8 @@
    after use. */
 void      ptr_free_clean (u_ptr_w *ptr_free);
 u_ptr_w * ptr_free_init (u_ptr_w *ptr_free, void *p);
-u_ptr_w * ptr_free_init_cast (u_ptr_w *ptr_free, const s_tag *tag);
+u_ptr_w * ptr_free_init_cast (u_ptr_w *ptr_free, const s_sym *type,
+                              const s_tag *tag);
 u_ptr_w * ptr_free_init_copy (u_ptr_w *ptr_free, const u_ptr_w *src);
 
 /* Heap-allocation functions, call ptr_free_delete after use. */
diff --git a/libc3/quote.c b/libc3/quote.c
index 7b087fd..053dc43 100644
--- a/libc3/quote.c
+++ b/libc3/quote.c
@@ -12,6 +12,7 @@
  */
 #include "assert.h"
 #include "quote.h"
+#include "sym.h"
 #include "tag.h"
 
 void quote_clean (s_quote *quote)
@@ -26,8 +27,12 @@ s_quote * quote_init (s_quote *quote, const s_tag *tag)
   return quote;
 }
 
-s_quote * quote_init_cast (s_quote *quote, const s_tag *tag)
+s_quote * quote_init_cast (s_quote *quote, const s_sym *type,
+                           const s_tag *tag)
 {
+  assert(quote);
+  assert(type);
+  assert(tag);
   switch (tag->type) {
   case TAG_QUOTE:
     return quote_init_copy(quote, &tag->data.quote);
@@ -36,7 +41,13 @@ s_quote * quote_init_cast (s_quote *quote, const s_tag *tag)
   }
   err_write_1("quote_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to Quote");
+  if (type == &g_sym_Quote)
+    err_puts(" to Quote");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka Quote");
+  }
   assert(! "quote_init_cast: cannot cast to Quote");
   return NULL;
 }
diff --git a/libc3/quote.h b/libc3/quote.h
index 51a4127..14806fd 100644
--- a/libc3/quote.h
+++ b/libc3/quote.h
@@ -19,7 +19,8 @@
 void      quote_clean (s_quote *quote);
 s_quote * quote_init (s_quote *quote, const s_tag *tag);
 s_quote * quote_init_1 (s_quote *quote, const s8 *p);
-s_quote * quote_init_cast (s_quote *quote, const s_tag *src);
+s_quote * quote_init_cast (s_quote *quote, const s_sym *type,
+                           const s_tag *src);
 s_quote * quote_init_copy (s_quote *quote, const s_quote *src);
 
 #endif /* LIBC3_QUOTE_H */
diff --git a/libc3/ratio.c b/libc3/ratio.c
index 1a0b8da..61519a9 100644
--- a/libc3/ratio.c
+++ b/libc3/ratio.c
@@ -513,25 +513,36 @@ s_ratio * ratio_sub (const s_ratio *a, const s_ratio *b,
   return dest;
 }
 
-f32 ratio_to_f32(const s_ratio *r)
+f32 ratio_to_f32 (const s_ratio *r)
 {
+  f32 numerator;
+  f32 denominator;
   assert(r);
   assert(integer_is_positive(&r->denominator));
-
-  f32 numerator = integer_to_f32(&r->numerator);
-  f32 denominator = integer_to_f32(&r->denominator);
-
+  numerator = integer_to_f32(&r->numerator);
+  denominator = integer_to_f32(&r->denominator);
   return numerator / denominator;
 }
 
-f64 ratio_to_f64(const s_ratio *r)
+f64 ratio_to_f64 (const s_ratio *r)
 {
+  f64 numerator;
+  f64 denominator;
   assert(r);
   assert(integer_is_positive(&r->denominator));
+  numerator = integer_to_f64(&r->numerator);
+  denominator = integer_to_f64(&r->denominator);
+  return numerator / denominator;
+}
 
-  f64 numerator = integer_to_f64(&r->numerator);
-  f64 denominator = integer_to_f64(&r->denominator);
-
+f128 ratio_to_f128 (const s_ratio *r)
+{
+  f128 numerator;
+  f128 denominator;
+  assert(r);
+  assert(integer_is_positive(&r->denominator));
+  numerator = integer_to_f128(&r->numerator);
+  denominator = integer_to_f128(&r->denominator);
   return numerator / denominator;
 }
 
diff --git a/libc3/ratio.h b/libc3/ratio.h
index 6ca3822..4d9cf54 100644
--- a/libc3/ratio.h
+++ b/libc3/ratio.h
@@ -51,16 +51,17 @@ bool    ratio_is_negative (const s_ratio *r);
 bool    ratio_is_zero (const s_ratio *r);
 f32     ratio_to_f32 (const s_ratio *r);
 f64     ratio_to_f64 (const s_ratio *r);
-sw      ratio_to_sw (const s_ratio *r);
-s64     ratio_to_s64 (const s_ratio *r);
-s32     ratio_to_s32 (const s_ratio *r);
-s16     ratio_to_s16 (const s_ratio *r);
+f128    ratio_to_f128 (const s_ratio *r);
 s8      ratio_to_s8 (const s_ratio *r);
-uw      ratio_to_uw (const s_ratio *r);
-u64     ratio_to_u64 (const s_ratio *r);
-u32     ratio_to_u32 (const s_ratio *r);
-u16     ratio_to_u16 (const s_ratio *r);
+s16     ratio_to_s16 (const s_ratio *r);
+s32     ratio_to_s32 (const s_ratio *r);
+s64     ratio_to_s64 (const s_ratio *r);
+sw      ratio_to_sw (const s_ratio *r);
 u8      ratio_to_u8 (const s_ratio *r);
+u16     ratio_to_u16 (const s_ratio *r);
+u32     ratio_to_u32 (const s_ratio *r);
+u64     ratio_to_u64 (const s_ratio *r);
+uw      ratio_to_uw (const s_ratio *r);
 
 /* Operators. */
 s_ratio * ratio_add (const s_ratio *a, const s_ratio *b,
diff --git a/libc3/s.c.in b/libc3/s.c.in
index 1af4c4a..050c589 100644
--- a/libc3/s.c.in
+++ b/libc3/s.c.in
@@ -21,8 +21,10 @@
 #include "ratio.h"
 #include "s_bits$.h"
 
-s_bits$ * s_bits$_init_cast (s_bits$ *s, const s_tag *tag)
+s_bits$ * s_bits$_init_cast
+(s_bits$ *s, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     *s = tag->data.bool ? 1 : 0;
diff --git a/libc3/s.h.in b/libc3/s.h.in
index 8b99d50..3eddf8d 100644
--- a/libc3/s.h.in
+++ b/libc3/s.h.in
@@ -16,7 +16,8 @@
 
 #include "types.h"
 
-s_bits$ * s_bits$_init_cast (s_bits$ *s, const s_tag *tag);
+s_bits$ * s_bits$_init_cast
+(s_bits$ *s, const s_sym *type, const s_tag *tag);
 s_bits$ * s_bits$_init_copy (s_bits$ *s, const s_bits$ *src);
 s_bits$ * s_bits$_random (s_bits$ *s);
 u_bits$ * s_bits$_random_uniform (s_bits$ *s, s_bits$ min, s_bits$ max);
diff --git a/libc3/s16.c b/libc3/s16.c
index 82080ea..5f7a099 100644
--- a/libc3/s16.c
+++ b/libc3/s16.c
@@ -21,8 +21,10 @@
 #include "ratio.h"
 #include "s16.h"
 
-s16 * s16_init_cast (s16 *s, const s_tag *tag)
+s16 * s16_init_cast
+(s16 *s, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     *s = tag->data.bool ? 1 : 0;
diff --git a/libc3/s16.h b/libc3/s16.h
index 9ab4e61..b5174bd 100644
--- a/libc3/s16.h
+++ b/libc3/s16.h
@@ -16,7 +16,8 @@
 
 #include "types.h"
 
-s16 * s16_init_cast (s16 *s, const s_tag *tag);
+s16 * s16_init_cast
+(s16 *s, const s_sym *type, const s_tag *tag);
 s16 * s16_init_copy (s16 *s, const s16 *src);
 s16 * s16_random (s16 *s);
 u16 * s16_random_uniform (s16 *s, s16 min, s16 max);
diff --git a/libc3/s32.c b/libc3/s32.c
index e4e4bcd..213633a 100644
--- a/libc3/s32.c
+++ b/libc3/s32.c
@@ -21,8 +21,10 @@
 #include "ratio.h"
 #include "s32.h"
 
-s32 * s32_init_cast (s32 *s, const s_tag *tag)
+s32 * s32_init_cast
+(s32 *s, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     *s = tag->data.bool ? 1 : 0;
diff --git a/libc3/s32.h b/libc3/s32.h
index 7b64000..b9b119f 100644
--- a/libc3/s32.h
+++ b/libc3/s32.h
@@ -16,7 +16,8 @@
 
 #include "types.h"
 
-s32 * s32_init_cast (s32 *s, const s_tag *tag);
+s32 * s32_init_cast
+(s32 *s, const s_sym *type, const s_tag *tag);
 s32 * s32_init_copy (s32 *s, const s32 *src);
 s32 * s32_random (s32 *s);
 u32 * s32_random_uniform (s32 *s, s32 min, s32 max);
diff --git a/libc3/s64.c b/libc3/s64.c
index 6dd7df0..644a445 100644
--- a/libc3/s64.c
+++ b/libc3/s64.c
@@ -21,8 +21,10 @@
 #include "ratio.h"
 #include "s64.h"
 
-s64 * s64_init_cast (s64 *s, const s_tag *tag)
+s64 * s64_init_cast
+(s64 *s, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     *s = tag->data.bool ? 1 : 0;
diff --git a/libc3/s64.h b/libc3/s64.h
index c864cf3..cb4c0f2 100644
--- a/libc3/s64.h
+++ b/libc3/s64.h
@@ -16,7 +16,8 @@
 
 #include "types.h"
 
-s64 * s64_init_cast (s64 *s, const s_tag *tag);
+s64 * s64_init_cast
+(s64 *s, const s_sym *type, const s_tag *tag);
 s64 * s64_init_copy (s64 *s, const s64 *src);
 s64 * s64_random (s64 *s);
 u64 * s64_random_uniform (s64 *s, s64 min, s64 max);
diff --git a/libc3/s8.c b/libc3/s8.c
index abe667b..9fb04c3 100644
--- a/libc3/s8.c
+++ b/libc3/s8.c
@@ -21,8 +21,10 @@
 #include "ratio.h"
 #include "s8.h"
 
-s8 * s8_init_cast (s8 *s, const s_tag *tag)
+s8 * s8_init_cast
+(s8 *s, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     *s = tag->data.bool ? 1 : 0;
diff --git a/libc3/s8.h b/libc3/s8.h
index 5c93749..9f7301e 100644
--- a/libc3/s8.h
+++ b/libc3/s8.h
@@ -16,7 +16,8 @@
 
 #include "types.h"
 
-s8 * s8_init_cast (s8 *s, const s_tag *tag);
+s8 * s8_init_cast
+(s8 *s, const s_sym *type, const s_tag *tag);
 s8 * s8_init_copy (s8 *s, const s8 *src);
 s8 * s8_random (s8 *s);
 u8 * s8_random_uniform (s8 *s, s8 min, s8 max);
diff --git a/libc3/str.c b/libc3/str.c
index f362688..17b8e5c 100644
--- a/libc3/str.c
+++ b/libc3/str.c
@@ -10,7 +10,7 @@
  * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
  * THIS SOFTWARE.
  */
-//#include <stdarg.h>
+#include <stdarg.h>
 #include <string.h>
 #include "alloc.h"
 #include "assert.h"
@@ -148,9 +148,10 @@ s_str * str_init_alloc (s_str *str, uw size, const char *p)
   return str;
 }
 
-s_str * str_init_cast (s_str *str, const s_tag *tag)
+s_str * str_init_cast (s_str *str, const s_sym *type, const s_tag *tag)
 {
   assert(str);
+  assert(type);
   assert(tag);
   switch (tag->type) {
   case TAG_S8:
@@ -182,7 +183,13 @@ s_str * str_init_cast (s_str *str, const s_tag *tag)
   }
   err_write_1("str_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to Str");
+  if (type == &g_sym_Str)
+    err_puts(" to Str");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka Str");
+  }
   assert(! "str_init_cast: cannot cast to Str");
   return NULL;
 }
@@ -485,7 +492,7 @@ bool str_parse_eval (const s_str *str, s_tag *dest)
     else {
       if (! tag_init_call_cast(&tmp, &g_sym_Str))
         goto restore;
-      tmp.data.call.arguments->tag = list->tag;
+      list_next(tmp.data.call.arguments)->tag = list->tag;
     }
     list = list_next(list);
     while (list) {
@@ -503,7 +510,7 @@ bool str_parse_eval (const s_str *str, s_tag *dest)
       else {
         if (! tag_init_call_cast(right, &g_sym_Str))
           goto restore;
-        right->data.call.arguments->tag = list->tag;
+        list_next(right->data.call.arguments)->tag = list->tag;
       }
       tmp = tmp1;
       list = list_next(list);
diff --git a/libc3/str.h b/libc3/str.h
index c07fbb5..e77866e 100644
--- a/libc3/str.h
+++ b/libc3/str.h
@@ -34,7 +34,8 @@ void    str_clean (s_str *str);
 s_str * str_init (s_str *str, char *free, uw size, const char *p);
 s_str * str_init_1 (s_str *str, char *free, const char *p);
 s_str * str_init_alloc (s_str *str, uw size, const char *p);
-s_str * str_init_cast (s_str *str, const s_tag *tag);
+s_str * str_init_cast (s_str *str, const s_sym *type,
+                       const s_tag *tag);
 s_str * str_init_cat (s_str *str, const s_str *a, const s_str *b);
 s_str * str_init_copy (s_str *str, const s_str *src);
 s_str * str_init_copy_1 (s_str *str, const char *p);
diff --git a/libc3/struct.c b/libc3/struct.c
index 5767c8a..a2e1ac3 100644
--- a/libc3/struct.c
+++ b/libc3/struct.c
@@ -113,19 +113,22 @@ s_struct * struct_init_1 (s_struct *s, const s8 *p)
   return s;
 }
 
-s_struct * struct_init_cast (s_struct *s, const s_tag *tag)
+s_struct * struct_init_cast (s_struct *s, const s_sym *type, const s_tag *tag)
 {
   assert(s);
   assert(tag);
   switch (tag->type) {
   case TAG_STRUCT:
-    return struct_init_copy(s, &tag->data.struct_);
+    if (type == tag->data.struct_.type->module)
+      return struct_init_copy(s, &tag->data.struct_);
   default:
     break;
   }
   err_write_1("struct_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to Struct");
+  err_write_1(" to ");
+  err_inspect_sym(&type);
+  err_write_1("\n");
   assert(! "struct_init_cast: cannot cast to Struct");
   return NULL;
 }
diff --git a/libc3/struct.h b/libc3/struct.h
index 1d139b3..c6f7d9a 100644
--- a/libc3/struct.h
+++ b/libc3/struct.h
@@ -24,7 +24,8 @@
 void       struct_clean (s_struct *s);
 s_struct * struct_init (s_struct *s, const s_sym *module);
 s_struct * struct_init_1 (s_struct *s, const s8 *p);
-s_struct * struct_init_cast (s_struct *s, const s_tag *tag);
+s_struct * struct_init_cast (s_struct *s, const s_sym *type,
+                             const s_tag *tag);
 s_struct * struct_init_copy (s_struct *s, const s_struct *src);
 s_struct * struct_init_from_lists (s_struct *s, const s_sym *module,
                                    const s_list *keys,
diff --git a/libc3/sw.c b/libc3/sw.c
index d2fa600..e79de95 100644
--- a/libc3/sw.c
+++ b/libc3/sw.c
@@ -21,8 +21,10 @@
 #include "ratio.h"
 #include "sw.h"
 
-sw * sw_init_cast (sw *s, const s_tag *tag)
+sw * sw_init_cast
+(sw *s, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     *s = tag->data.bool ? 1 : 0;
diff --git a/libc3/sw.h b/libc3/sw.h
index 14d155b..38cc5a2 100644
--- a/libc3/sw.h
+++ b/libc3/sw.h
@@ -16,7 +16,8 @@
 
 #include "types.h"
 
-sw * sw_init_cast (sw *s, const s_tag *tag);
+sw * sw_init_cast
+(sw *s, const s_sym *type, const s_tag *tag);
 sw * sw_init_copy (sw *s, const sw *src);
 sw * sw_random (sw *s);
 uw * sw_random_uniform (sw *s, sw min, sw max);
diff --git a/libc3/sym.c b/libc3/sym.c
index f25bbd4..857fb02 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -251,9 +251,11 @@ const s_sym ** sym_init_1 (const s_sym **sym, const char *p)
   return sym;
 }
 
-const s_sym ** sym_init_cast (const s_sym **sym, const s_tag *tag)
+const s_sym ** sym_init_cast (const s_sym **sym, const s_sym *type,
+                              const s_tag *tag)
 {
   assert(sym);
+  assert(type);
   assert(tag);
   switch (tag->type) {
   case TAG_STR:
@@ -265,7 +267,13 @@ const s_sym ** sym_init_cast (const s_sym **sym, const s_tag *tag)
   }
   err_write_1("sym_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to Sym");
+  if (type == &g_sym_Sym)
+    err_puts(" to Sym");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka Sym");
+  }
   assert(! "sym_init_cast: cannot cast to Sym");
   return NULL;
 }
diff --git a/libc3/sym.h b/libc3/sym.h
index 4f8cf97..8ac5f8e 100644
--- a/libc3/sym.h
+++ b/libc3/sym.h
@@ -108,7 +108,8 @@ extern const s_sym g_sym_x;
 
 const s_sym  * sym_1 (const char *p);
 const s_sym ** sym_init_1 (const s_sym **sym, const char *p);
-const s_sym ** sym_init_cast (const s_sym **sym, const s_tag *tag);
+const s_sym ** sym_init_cast (const s_sym **sym, const s_sym *type,
+                              const s_tag *tag);
 const s_sym ** sym_init_copy (const s_sym **sym,
                               const s_sym * const *src);
 void           sym_init_g_sym (void);
diff --git a/libc3/tuple.c b/libc3/tuple.c
index e1fb62d..0f30abe 100644
--- a/libc3/tuple.c
+++ b/libc3/tuple.c
@@ -17,6 +17,7 @@
 #include "buf_inspect.h"
 #include "buf_parse.h"
 #include "io.h"
+#include "sym.h"
 #include "tuple.h"
 #include "tag.h"
 
@@ -86,7 +87,8 @@ s_tuple * tuple_init_2 (s_tuple *tuple, const s_tag *a, const s_tag *b)
   return tuple;
 }
 
-s_tuple * tuple_init_cast (s_tuple *tuple, const s_tag *tag)
+s_tuple * tuple_init_cast (s_tuple *tuple, const s_sym *type,
+                           const s_tag *tag)
 {
   switch (tag->type) {
   case TAG_TUPLE:
@@ -96,7 +98,13 @@ s_tuple * tuple_init_cast (s_tuple *tuple, const s_tag *tag)
   }
   err_write_1("tuple_init_cast: cannot cast ");
   err_write_1(tag_type_to_string(tag->type));
-  err_puts(" to Tuple");
+  if (type == &g_sym_Tuple)
+    err_puts(" to Tuple");
+  else {
+    err_write_1(" to ");
+    err_inspect_sym(&type);
+    err_puts(" aka Tuple");
+  }
   assert(! "tuple_init_cast: cannot cast to Tuple");
   return NULL;
 }
diff --git a/libc3/tuple.h b/libc3/tuple.h
index ce576e0..3ca22ab 100644
--- a/libc3/tuple.h
+++ b/libc3/tuple.h
@@ -26,7 +26,8 @@
 s_tuple * tuple_init (s_tuple *tuple, uw count);
 s_tuple * tuple_init_1 (s_tuple *tuple, const char *p);
 s_tuple * tuple_init_2 (s_tuple *tuple, const s_tag *a, const s_tag *b);
-s_tuple * tuple_init_cast (s_tuple *tuple, const s_tag *tag);
+s_tuple * tuple_init_cast (s_tuple *tuple, const s_sym *type,
+                           const s_tag *tag);
 s_tuple * tuple_init_copy (s_tuple *tuple, const s_tuple *src);
 void      tuple_clean (s_tuple *tuple);
 
diff --git a/libc3/u.c.in b/libc3/u.c.in
index 1423f0a..52cfba1 100644
--- a/libc3/u.c.in
+++ b/libc3/u.c.in
@@ -20,8 +20,10 @@
 #include "tag.h"
 #include "u_bits$.h"
 
-u_bits$ * u_bits$_init_cast (u_bits$ *u, const s_tag *tag)
+u_bits$ * u_bits$_init_cast
+(u_bits$ *u, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     *u = tag->data.bool ? 1 : 0;
diff --git a/libc3/u.h.in b/libc3/u.h.in
index 3b3739e..1eca73b 100644
--- a/libc3/u.h.in
+++ b/libc3/u.h.in
@@ -16,7 +16,9 @@
 
 #include "types.h"
 
-u_bits$ * u_bits$_init_cast (u_bits$ *u, const s_tag *tag);
+u_bits$ * u_bits$_init_cast
+(u_bits$ *u, const s_sym *type, const s_tag *tag);
+
 u_bits$ * u_bits$_init_copy (u_bits$ *u, const u_bits$ *src);
 u_bits$ * u_bits$_random (u_bits$ *u);
 u_bits$ * u_bits$_random_uniform (u_bits$ *u, u_bits$ max);
diff --git a/libc3/u16.c b/libc3/u16.c
index 3df8aa7..66afa49 100644
--- a/libc3/u16.c
+++ b/libc3/u16.c
@@ -20,8 +20,10 @@
 #include "tag.h"
 #include "u16.h"
 
-u16 * u16_init_cast (u16 *u, const s_tag *tag)
+u16 * u16_init_cast
+(u16 *u, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     *u = tag->data.bool ? 1 : 0;
diff --git a/libc3/u16.h b/libc3/u16.h
index 35e2e80..a53a97a 100644
--- a/libc3/u16.h
+++ b/libc3/u16.h
@@ -16,7 +16,9 @@
 
 #include "types.h"
 
-u16 * u16_init_cast (u16 *u, const s_tag *tag);
+u16 * u16_init_cast
+(u16 *u, const s_sym *type, const s_tag *tag);
+
 u16 * u16_init_copy (u16 *u, const u16 *src);
 u16 * u16_random (u16 *u);
 u16 * u16_random_uniform (u16 *u, u16 max);
diff --git a/libc3/u32.c b/libc3/u32.c
index 04f2656..9c01855 100644
--- a/libc3/u32.c
+++ b/libc3/u32.c
@@ -20,8 +20,10 @@
 #include "tag.h"
 #include "u32.h"
 
-u32 * u32_init_cast (u32 *u, const s_tag *tag)
+u32 * u32_init_cast
+(u32 *u, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     *u = tag->data.bool ? 1 : 0;
diff --git a/libc3/u32.h b/libc3/u32.h
index a58aae1..ece4abe 100644
--- a/libc3/u32.h
+++ b/libc3/u32.h
@@ -16,7 +16,9 @@
 
 #include "types.h"
 
-u32 * u32_init_cast (u32 *u, const s_tag *tag);
+u32 * u32_init_cast
+(u32 *u, const s_sym *type, const s_tag *tag);
+
 u32 * u32_init_copy (u32 *u, const u32 *src);
 u32 * u32_random (u32 *u);
 u32 * u32_random_uniform (u32 *u, u32 max);
diff --git a/libc3/u64.c b/libc3/u64.c
index 2e93fdb..87c64e8 100644
--- a/libc3/u64.c
+++ b/libc3/u64.c
@@ -20,8 +20,10 @@
 #include "tag.h"
 #include "u64.h"
 
-u64 * u64_init_cast (u64 *u, const s_tag *tag)
+u64 * u64_init_cast
+(u64 *u, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     *u = tag->data.bool ? 1 : 0;
diff --git a/libc3/u64.h b/libc3/u64.h
index 6033877..05802cb 100644
--- a/libc3/u64.h
+++ b/libc3/u64.h
@@ -16,7 +16,9 @@
 
 #include "types.h"
 
-u64 * u64_init_cast (u64 *u, const s_tag *tag);
+u64 * u64_init_cast
+(u64 *u, const s_sym *type, const s_tag *tag);
+
 u64 * u64_init_copy (u64 *u, const u64 *src);
 u64 * u64_random (u64 *u);
 u64 * u64_random_uniform (u64 *u, u64 max);
diff --git a/libc3/u8.c b/libc3/u8.c
index d226ccd..090aa92 100644
--- a/libc3/u8.c
+++ b/libc3/u8.c
@@ -20,8 +20,10 @@
 #include "tag.h"
 #include "u8.h"
 
-u8 * u8_init_cast (u8 *u, const s_tag *tag)
+u8 * u8_init_cast
+(u8 *u, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     *u = tag->data.bool ? 1 : 0;
diff --git a/libc3/u8.h b/libc3/u8.h
index 91a7d92..0d6622e 100644
--- a/libc3/u8.h
+++ b/libc3/u8.h
@@ -16,7 +16,9 @@
 
 #include "types.h"
 
-u8 * u8_init_cast (u8 *u, const s_tag *tag);
+u8 * u8_init_cast
+(u8 *u, const s_sym *type, const s_tag *tag);
+
 u8 * u8_init_copy (u8 *u, const u8 *src);
 u8 * u8_random (u8 *u);
 u8 * u8_random_uniform (u8 *u, u8 max);
diff --git a/libc3/uw.c b/libc3/uw.c
index 5b6e825..dfc0974 100644
--- a/libc3/uw.c
+++ b/libc3/uw.c
@@ -20,8 +20,10 @@
 #include "tag.h"
 #include "uw.h"
 
-uw * uw_init_cast (uw *u, const s_tag *tag)
+uw * uw_init_cast
+(uw *u, const s_sym *type, const s_tag *tag)
 {
+  (void) type;
   switch (tag->type) {
   case TAG_BOOL:
     *u = tag->data.bool ? 1 : 0;
diff --git a/libc3/uw.h b/libc3/uw.h
index 868a43e..06b1fb9 100644
--- a/libc3/uw.h
+++ b/libc3/uw.h
@@ -16,7 +16,9 @@
 
 #include "types.h"
 
-uw * uw_init_cast (uw *u, const s_tag *tag);
+uw * uw_init_cast
+(uw *u, const s_sym *type, const s_tag *tag);
+
 uw * uw_init_copy (uw *u, const uw *src);
 uw * uw_random (uw *u);
 uw * uw_random_uniform (uw *u, uw max);
diff --git a/libc3/void.c b/libc3/void.c
index ca43b28..3074a63 100644
--- a/libc3/void.c
+++ b/libc3/void.c
@@ -12,8 +12,9 @@
  */
 #include "void.h"
 
-void * void_init_cast (void *v, const s_tag *src)
+void * void_init_cast (void *v, const s_sym *type, const s_tag *src)
 {
   (void) src;
+  (void) type;
   return v;
 }
diff --git a/libc3/void.h b/libc3/void.h
index a55318a..28e0c9f 100644
--- a/libc3/void.h
+++ b/libc3/void.h
@@ -22,6 +22,6 @@
 #include "types.h"
 
 /* Operators. */
-void * void_init_cast (void *v, const s_tag *src);
+void * void_init_cast (void *v, const s_sym *type, const s_tag *src);
 
 #endif /* LIBC3_VOID_H */