Conversation
This adds and solves a new 'magic' constraint,
`Type.Data.Symbol.ConsSymbol`, with the following functional
dependencies:
class ConsSymbol (head :: Symbol)
(tail :: Symbol)
(sym :: Symbol) | sym -> head tail, head tail -> sym
* The `head tail -> sym` direction works like `AppendSymbol`, but only
resolves when `head` is a singleton symbol.
* The `sym -> head tail` direction deconstructs the symbol into its
first character and the remaining string.
|
I'd be happy to add some examples, but I'm not too sure how I would depend on the new type-level prelude at this point |
|
Here's another example using it |
| let args = [arg0, arg1, TypeLevelString (lhs <> rhs)] | ||
| in [TypeClassDictionaryInScope AppendSymbolInstance [] C.AppendSymbol args Nothing] | ||
| forClassName _ C.ConsSymbol [arg0, arg1, arg2] | ||
| | Just (arg0', arg1', arg2') <- (consSymbol arg0 arg1 arg2) = |
There was a problem hiding this comment.
The parens are redundant here.
|
|
||
| consSymbol :: Type -> Type -> Type -> Maybe (Type, Type, Type) | ||
| consSymbol _ _ arg@(TypeLevelString s) = do | ||
| (h, t) <- (mkTLString . T.singleton *** mkTLString) <$> (T.uncons =<< decodeString s) |
There was a problem hiding this comment.
This is a little hard to read. What about this?
do (h, t) <- T.uncons =<< decodeString s
pure (mkTLString (T.singleton h), mkTLString t, arg)| consSymbol arg1@(TypeLevelString h) arg2@(TypeLevelString t) _ = do | ||
| h' <- decodeString h | ||
| t' <- decodeString t | ||
| if (T.length h' == 1) |
paf31
left a comment
There was a problem hiding this comment.
Looks great, thanks! Couple of minor, non-blocking comments. I'll add this to the 0.12.0 queue.
|
Thanks for the comments, I've fixed them! |
|
On a related note, I think it would be better to have a |
|
Thanks! We have some time before 0.12.0 is properly released to discuss the |
|
@kcsongor Would you mind adding yourself to |
|
Great, that sounds good |
This adds and solves a new 'magic' constraint,
Type.Data.Symbol.ConsSymbol, with the following functionaldependencies:
The
head tail -> symdirection works likeAppendSymbol, but onlyresolves when
headis a singleton symbol.The
sym -> head taildirection deconstructs the symbol into itsfirst character and the remaining string.
The relevant PR for the typelevel-prelude:
purescript/purescript-typelevel-prelude#24
I put up an example that uses this class at
https://github.com/kcsongor/purescript-record-format