Skip to content

show how to use GADTs and type indices to dispatch commands - #229

Merged
bookshelfdave merged 1 commit into
dp_help_refactorfrom
dp_help_refactor_GADTs
Jul 5, 2020
Merged

bookshelfdave merged 1 commit into
dp_help_refactorfrom
dp_help_refactor_GADTs

Conversation

@byorgey

@byorgey byorgey commented Jul 4, 2020

Copy link
Copy Markdown
Member

This way we don't need the toTag stuff, and we don't need any
handleXXXWrapper functions that match on just one thing and return ()
for everything else.

The key idea is that both commands and and REPLExprs are indexed by an
enumeration, so each REPLExpr and the command that can process it
share a label. The 'dispatch' function uses the magic 'gcast'
function from Data.Typeable to find the first command which has a
matching type index, and uses its 'action' to process
the (guaranteed-matching) REPLExpr. Each 'handleXXX' function
declares that it only handles REPLExprs with a particular type index,
which means it only has to match on the one constructor which actually
has that type index.

This way we don't need the toTag stuff, and we don't need any
handleXXXWrapper functions that match on just one thing and return ()
for everything else.

The key idea is that both commands and and REPLExprs are indexed by an
enumeration, so each REPLExpr and the command that can process it
share a label.  The 'dispatch' function uses the magic 'gcast'
function from Data.Typeable to find the first command which has a
matching type index, and uses its 'action' to process
the (guaranteed-matching) REPLExpr.  Each 'handleXXX' function
declares that it only handles REPLExprs with a particular type index,
which means it only has to match on the one constructor which actually
has that type index.
@bookshelfdave

Copy link
Copy Markdown
Collaborator

this is really interesting, and it looks like I have some reading to do :-)

I'll merge into my wip branch and refactor all the rest. Thanks @byorgey!

@bookshelfdave
bookshelfdave merged commit 73b849f into dp_help_refactor Jul 5, 2020
bookshelfdave pushed a commit that referenced this pull request Jul 6, 2020
GADT/typed indices implementation from byorgey via #229
bookshelfdave pushed a commit that referenced this pull request Jul 6, 2020
GADT/typed indices implementation from byorgey via #229
bookshelfdave pushed a commit that referenced this pull request Jul 6, 2020
GADT/typed indices implementation from byorgey via #229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants