purescript / purescript-typelevel-prelude

Types and kinds for basic type-level programming
BSD 3-Clause "New" or "Revised" License
63 stars 21 forks source link

Feature Request: Symbol Reverse #40

Open eric-corumdigital opened 6 years ago

eric-corumdigital commented 6 years ago
class Reverse (s :: Symbol) (r :: Symbol) | s -> r, r -> s
instance reverseNil :: Reverse "" ""
else instance reverseCons :: (Symbol.Cons h t s, Reverse t u, Symbol.Append u h r) => Reverse s r
LiamGoodacre commented 6 years ago

This implementation doesn't appear to be bidirectional:

Forwards:

eg1 :: Unit
eg1 = unit :: forall t . Reverse "Apple" t => Warn (Text t) => Unit

-- A custom warning occurred while solving type class constraints:
--   elppA

Backwards:

eg2 :: Unit
eg2 = unit :: forall t . Reverse t "Banana" => Warn (Text t) => Unit
-- No type class instance was found for
--   Prim.Symbol.Cons t0 t1 t2

The issue is that Append requires at least two arguments to work out the third.

eric-corumdigital commented 6 years ago

Yeah suppose so. I'll share the more elaborate implementation when I am able.

JordanMartinez commented 2 years ago

See #51