File: type_def.out.rb

package info (click to toggle)
ruby-algebrick 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: ruby: 1,614; makefile: 3
file content (21 lines) | stat: -rw-r--r-- 1,039 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Let's define some types
Maybe = Algebrick.type do
  variants None = atom,
           Some = type { fields Numeric }
end                                                # => Maybe(None | Some)

# where the Maybe actually is:
Maybe.class                                        # => Algebrick::ProductVariant
Maybe.class.superclass                             # => Algebrick::Type
Maybe.class.superclass.superclass                  # => Module
Maybe.class.superclass.superclass.superclass       # => Object

# if there is a circular dependency you can define the dependent types inside the block like this:
Tree = Algebrick.type do |tree|
  variants Empty = type,
           Leaf  = type { fields Integer },
           Node  = type { fields tree, tree }
end                                                # => Tree(Empty | Leaf | Node)
Empty                                              # => Empty
Leaf                                               # => Leaf(Integer)
Node                                               # => Node(Tree, Tree)