I think there is a misunderstanding about what 'unit' is.
Shen doesn't define `unit` anywhere, it only exists as a convention,
when you use `unit` you are just using a symbol that has not been
taken by any type definition, you may use `antti` if you want with the
same result.
Try this in the REPL:
- Enable `(tc +)`
- Enable `(spy +)`
- Attempt various combinations of `SomeValue : unit`
You will see that the typechecker will throw an error every time it
tries to verify that one value is of type `unit`, thats because there
is no such thing as a value of type `unit` (at least not until you
define your own theory).
Now, what follows if a very rough picture of whats going on, and I
hope it helps to make things clearer instead of more confusing, my
advice is to re-read the relevant sections of the Shen book and play
more with `(spy +)` to develop your intuition.
The types of the dict operations are:
<-dict : { (dict A B) --> A --> B }
dict-> : { (dict A B) --> A --> B --> B }
Since your dict is of type `(dict symbol unit)`, for dicts of such
type then any expression that looks like `(<-dict Dict Symbol)` will
look like this to the typechecker:
(dict A1 B1) --> A2 --> B2
(dict symbol unit) --> symbol --> unit
Every A has to match every other A (either by being the same or
compatible), same for every B.
A1 matches A2 and B1 matches B2, thats good, the result is tagged as
`unit`, thats why you see "Antti" : unit (even if we know "Antti" is a
string, the typechecker will not try to validate this because you are
not using the value for anything yet).
For `(<-dict Dict Symbol String)` the story is different:
(dict A1 B1) --> A2 --> B2 --> B3
(dict symbol unit) --> symbol --> string --> unit
Here not all B match, we have B1 and B3 being `unit` (thats ok), but
B2 is `string` (not good), and that is where the typechecking is
failing.
One of the options you have is to make a function that changes the
type of a value to `unit`:
(define mkunit X -> X)
(datatype mkunit
__________
mkunit : (A --> unit);)
which will allow this to work:
(dict-> (value *d*) surname (mkunit "Y"))
Another option is to add a definition for the specific case of dicts
with values of type `unit`.
> --
> You received this message because you are subscribed to the Google Groups
> "Shen" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
qilang+un...@googlegroups.com.
> To post to this group, send email to
qil...@googlegroups.com.
> Visit this group at
https://groups.google.com/group/qilang.
> For more options, visit
https://groups.google.com/d/optout.
--
BD