Skip to content

Commit ad8da2b

Browse files
committed
More informative README (issue #23)
1 parent 0ffff3e commit ad8da2b

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

README.md

+22-9
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,29 @@
55
[![Build Status](https://github.com/SciML/Static.jl/workflows/CI/badge.svg)](https://github.com/SciML/Static.jl/actions)
66
[![Coverage](https://codecov.io/gh/SciML/Static.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/SciML/Static.jl)
77

8-
`Static` defines a limited set of statically parameterized types and a common interface that is shared between them. Defining a new static type that conforms with this interface only requires defining the following:
8+
`Static` defines a set of types (`True`, `False`, `StaticInt{value::Int}`, `StaticFloat64{value::Float64}`, `StaticSymbol{value::Symbol}`) that may be dispatched on (similar to `Base.Val{value}`). Unlike `Base.Val`, instances of these types provide "static" values (meaning known at compile time) that in many cases work interchangeably with dynamic values (meaning the value is known at runtime but not compile time). This is particularly useful when designing types whose fields may be dynamically or statically known, such as a range whose size may be dynamic or statically known.
99

10-
* `Static.static(::T)` - given the non-static type `T` return its static counterpart.
11-
* `Static.is_static(::Type{S})` - given the static type `S` return `True()`.
12-
* `Static.known(::Type{S})`- given the static type `S` return the known non-static value.
13-
14-
Fore example, the following would appropriately define the interface for `StaticChar`
10+
Generic conversion to static values, dynamic values, and compile time known values is accomplished with the methods `static`, `dynamic`, and `known`, respectively.
1511

1612
```julia
17-
Static.static(x::Char) = StaticChar(x)
18-
Static.is_static(::Type{T}) where {T<:StaticChar} = True()
19-
Static.known(::Type{StaticChar{C}}) where {C} = C::Char
13+
julia> using Static
14+
15+
julia> static(1)
16+
static(1)
17+
18+
julia> dynamic(static(1))
19+
1
20+
21+
julia> dynamic(1)
22+
1
23+
24+
julia> typeof(static(1))
25+
StaticInt{1}
26+
27+
julia> known(typeof(static(1)))
28+
1
29+
30+
julia> known(typeof(1)) === nothing # `Int` has no compile time known value
31+
true
32+
2033
```

0 commit comments

Comments
 (0)