Adventures in type checking
Blockly User Summit 2019
Mark Gibson
About Us
TODO:
Who Adaptavist are (GROUP PHOTO)
AutoBlocks
Why are types important to us?
Type checking in Blockly
Type checking in Blockly
{
"type": "mouth",
"message0": "mouth %1",
"args0": [
{
"type": "input_value",
"name": "CONSUME",
"check": [
"Air",
"Food",
"Drink"
]
}
]
}
{
"type": "peas",
"message0": "peas",
"output": [
"Nutritious",
"Vegetable",
"Food",
"Legume",
"Healthy"
]
}
It's all about the Venn
Input Output
It's all about the Venn
Input Output
mouth peas
Nutritious
Air Vegetable
Food
Drink Legume
Healthy
It's all about the Venn
Input Output
fussy mouth peas
Air Vegetable
Potato Nutritious
Breaded Food
Sugary Healthy
Unhealthy Legume
Examples from AutoBlocks
Examples from AutoBlocks
Input:
Output:
Examples from AutoBlocks
Input:
["Project", "String"]
Output:
["String"]
Examples from AutoBlocks
Input:
["IssueType", "String"]
Output:
["IssueType"]
Examples from AutoBlocks
Input:
["Issue", "String"]
Output:
["Issue"]
from a variable
Lists and loops
Lists and loops
No items = unknown types
any
?
List of ?
Lists and loops
Types flow from right to left
Issue
Issue
List of Issues
Lists and loops
What other items can we add?
List of Issues and ?
?
?
Lists and loops
NO!
List of Issues and ?
?
?
Lists and loops
Restricted inputs
List of Issues
Issue
Issue
How did we implement this?
How did we implement this?
How did we implement this?
Higher Types
Inputs
Outputs
Higher Types
Inputs
Accept a list of anything:
["List:*"]
Outputs
Higher Types
Inputs
Accept a list of anything:
["List:*"]
Only accept a list of a specific type:
["List:Issue"]
Outputs
Higher Types
Inputs
Accept a list of anything:
["List:*"]
Only accept a list of a specific type:
["List:Issue"]
Accept one or many of a specific type:
["Issue", "List:Issue"]
Outputs
Higher Types
Inputs
Accept a list of anything:
["List:*"]
Only accept a list of a specific type:
["List:Issue"]
Accept one or many of a specific type:
["Issue", "List:Issue"]
Outputs
Returning a specific type:
["List:Issue", "List:*"]
Allows connection to input:
Higher Types
Input Output
for each create list with
List:* List:Issue
Higher Types - wild ideas
One
["1:*"]
["1:Something"]
Many
["N:*"]
["N:Something"]
One or Many
Input:
["X:*"]
["X:Something"]
Output:
["1:Something", "X:Something", "1:*", "X:*"]
["N:Something", "X:Something", "N:*", "X:*"]
type_from - Blockly Extension
type_from - Blockly Extension
Inherit an input check, output type, or variable field type from�the output of the block connected to another input!
["From:INPUT"]
["From:INPUT+HigherType"]
["From:INPUT-HigherType"]
["From:INPUT^HigherType"]
type_from - Blockly Extension
{
"type": "loop_foreach",
"message0": "for each %1 in %2",
"args0": [{
"type": "field_variable",
"name": "ITEM",
"variable": "item_#",
"variableTypes": [
"From:LIST-List"
],
"defaultType": [
"From:LIST-List"
],
"definition": true
}, {
"type": "input_value",
"name": "LIST",
"check": "List:*"
}],
"extensions": [
"type_from"
]
}
{
"type": "list_create_with",
"output": "From:ADD0+List",
"extensions": [
"type_from"
],
"mutator": "create_with_list_mutator"
}
The ADD0 input will be added by the mutator
BUT...
Lists as inputs
Lists as inputs
Lists as inputs
Types should flow left to right
List of Components
Lists as inputs
Types should flow left to right
List of Components
Component
Lists as inputs
But they don't 😒
Lists as inputs
🤷
Variables in Blockly
Variables in Blockly
Variables in Blockly
Why is this problem?
Variables in Blockly
Why is this problem?
Variables in Blockly
Why is this problem?
Variables in Blockly
Variable Field
["Issue", "IssueEvent"]
Variables in Blockly
Output
["Issue", "IssueEvent"]
Variables in Blockly
Multi-type Variables - Monkey Patch
Issue #1997
https://github.com/google/blockly/issues/1997
Conclusion
Conclusion
Types are hard
Conclusion
Types are hard
The current type system in Blockly is not enough
Conclusion
Types are hard
The current type system in Blockly is not enough
Need a variable type model consistent with connection type checking
Conclusion
Types are hard
The current type system in Blockly is not enough
Need a variable type model consistent with connection type checking
And/or…
Questions?
Adventures in type checking
Blockly User Summit 2019
Mark Gibson