Skip to main content

how to use

## create Type

>>> from miniadt import ADTTypeProvider, dispatchmethod
>>> TreeType = ADTTypeProvider("Tree")

>>> Node = TreeType("Node", "e children")
>>> Leaf = TreeType("Leaf", "e")


## printing value

>>> Leaf(e=10)
Leaf(e=10)
>>> Node(e=10, children=[Leaf(e=20)])
Node(e=10, children=[Leaf(e=20)])


## use pattern match

>>> @TreeType.match
... class depth(object):
...     @dispatchmethod
...     def Node(e, children):
...         return max(depth(e)for e in children) + 1
...
...     @dispatchmethod
...     def Leaf(e):
...         return 1

>>> depth(Leaf(e=10))
1

>>> depth(Node(e=10, children=[Leaf(e=20), Node(e=30, children=[Leaf(e=40)])]))
3

miniadt has comprehensive check function.

## not comprehensive definition on pattern matching function error is occur

### 1. lack of dispatch candidates
>>> class invalid_dispatch(object):
...     @dispatchmethod
...     def Node(e, children):
...         return "foo"

>>> TreeType.match(invalid_dispatch)
Traceback (most recent call last):
 ...
miniadt.NotComprehensive: expected=['Node', 'Leaf'] != actual=['Node']


### 2. dispatch function's arguments are invalid.
>>> class invalid_dispatch2(object):
...     @dispatchmethod
...     def Node(e):  ## correct argsspec is "e, children"
...         return "foo"
...     @dispatchmethod
...     def Leaf(e):
...         return "foo"

>>> TreeType.match(invalid_dispatch2)
Traceback (most recent call last):
 ...
miniadt.NotComprehensive: on Tree.Node:  expected=['e', 'children'] != actual=['e']

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

miniadt-0.2.tar.gz (4.4 kB view details)

Uploaded Source

File details

Details for the file miniadt-0.2.tar.gz.

File metadata

  • Download URL: miniadt-0.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for miniadt-0.2.tar.gz
Algorithm Hash digest
SHA256 734fe73d7e88646f76f9986c1a158da6c4cd9e75c46627cfde137bd9fd7e25a1
MD5 ffe97dc2952c036f5f3a735eee081739
BLAKE2b-256 eb4c907ceeffe7c801a1977d0ac775212d3a3ed41d881917469246deceac41ce

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

1 file

0.3.0

1 file

0.2.1

1 file

This release

0.2 This release

1 file

0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page