User loginNavigation |
The Type of 42The following is a reposting from my blog at http://www.artima.com/weblogs/viewpost.jsp?thread=182140. When I was designing Cat I started with the assumption that the type of a number such as 42, must be a function which pushes a primitive integer type onto the stack. So the type of 42 would be: 42 : ()->(int) The type of a function which yielded 42 would be: [42] : ()->(()->(int)) In Joy the operation for evaluating functions is "i". The equivalent in Cat is "eval". The type of eval in Cat currently is: eval : (A (A:any*)->(B:any*))->(B) This meant that the following was badly typed in Cat: 42 eval This is because eval expected a function on the top of the stack, but 42 produced a primitive on the top of the stack. You would have to instead write: [42] eval The decision for this type design was based on two things:
In assembly an operation which yields 42 and the value 42 are very different things. My thought was that I wanted to be able to trivially map Cat functions to assembly code. My concern is that the execution loop of an assembly program where values were executable would be non-trivial. I assumed you would need a switch statement and this would signficiantly hurt performance (Cat is striving to become a full competitor with real assembly code, so performance is a big concern). I am no longer convinced that this would actually be a problem. The first issue is writing the type of numbers. It appears that what is needed is the ability to name new types and express them recursively: 42 : int; int = ()->(int); The next challenge is converting to assembly code. I haven't worked out all of the details, but I believe that when generating assembly, I need to simply insert type conversion routines at key places (i.e. where an integer is being executed, or treated like a function). Do all this seem sane and rational? By cdiggins at 2006-10-25 20:34 | LtU Forum | previous forum topic | next forum topic | other blogs | 6246 reads
|
Browse archives
Active forum topics |
Recent comments
27 weeks 2 days ago
27 weeks 2 days ago
27 weeks 2 days ago
49 weeks 3 days ago
1 year 1 week ago
1 year 3 weeks ago
1 year 3 weeks ago
1 year 5 weeks ago
1 year 10 weeks ago
1 year 10 weeks ago