3 ms·
> If, instead of the above example, you declared x of type (List Any), the list '(1 2 "hello") could still be bound to it, and the call to car would still be ac
by urs2102 11y ago
> If, instead of the above example, you declared x of type (List Any), the list '(1 2 "hello") could still be bound to it, and the call to car would still be accepted by the compiler, but not the call to sqrt.
(sqrt (car '(1 2 "hello"))
So in this example, since it's a (List Any), in order to get this to work would we cast the Any to be an Int to then put it through sqrt?
(sqrt (int (car '(1 2 "hello")))
Also checked out out FMJ - super interesting. I do like the way you used Prolog's unification as way to describe successful type matching. How far along is your work with FMJ?
- DonaldFisk 11y ago> So in this example, since it's a (List Any), in order to get this to work would we cast the Any to be an Int to then put it through sqrt? I wouldn't recommend you use casting the way it's done in C. It defeats the purpose of having a strong type system if you can change the types like that. Having a function which checks the type and gives an error if it's not the type you expect is, I think, a better approach. I'm still actively developing Full Metal Jacket. Glad you find it interesting. An interpreter for the basic language is almost complete. I'll soon add to my tutorials (http://web.onetel.com/~hibou/fmj/tutorials/TOC.html http://web.onetel.com/~hibou/fmj/tutorials/TOC.html) how to do inlining and substitution macros, and how to define new types. Then I'll make my code more robust, possibly add a compiler, and arrange a release on a shared-source licence.
- urs2102 11y agoOh yeah, my mistake - you're totally right. So in this case what type does car output (or how do I write the type definition for car), because it can't output multiple types otherwise I wouldn't be able to check its value at compile time? And yeah, Full Metal Jacket seemed cool (and it's a great name). Do post it here when you start putting those tutorials up!