purescript-typelevel-prelude icon indicating copy to clipboard operation
purescript-typelevel-prelude copied to clipboard

Feature Request: Symbol Reverse

Open eric-corumdigital opened this issue 7 years ago • 3 comments

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

eric-corumdigital avatar Oct 25 '18 14:10 eric-corumdigital

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.

LiamGoodacre avatar Oct 26 '18 12:10 LiamGoodacre

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

eric-corumdigital avatar Oct 31 '18 17:10 eric-corumdigital

See #51

JordanMartinez avatar Dec 04 '21 04:12 JordanMartinez