The Julia documentation says:
A primitive type is a concrete type whose data consists of plain old bits. Classic examples of primitive types are integers and floating-point values. Unlike most languages, Julia lets you declare your own primitive types, rather than providing only a fixed set of built-in ones. In fact, the standard primitive types are all defined in the language itself:
I'm unable to find an example of how to do this, though, either in the docs or in the source code or anywhere else. What I'm looking for is an example of how to declare a primitive type, and how to subsequently implement a function or method on that type that works by manipulating those bits.
Is anyone able to point me towards an example? Thanks.
Edit: It's clear how to declare a primitive type, as there are examples immediately below the above quote in the doc. I'm hoping for information about how to subsequently manipulate them. For example, say I wanted to (pointlessly) implement my own primitive type MyInt8
. I could declare that with primitive type MyInt8 <: Signed 8 end
. But how would I subsequently implement a function myplus
that manipulated the bits within Myint8
?
PS in case it helps, the reason I'm asking is not because I need to do anything specific in Julia; I'm designing my own language for fun, and am researching how other languages implement various things.
Myint8
type, you can look at this question (made just of yesterday): stackoverflow.com/questions/47422089/… – Antonello+
by manipulating the fields of the typeFoo
- I'm interested in doing a similar thing, but with a primitive type, and manipulating the bits of that type. – Sam Roberts