{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Data.Function.FastMemo.List (AsList (..)) where

import Data.Function.FastMemo.Class (Memoizable (..))
import Data.List.NonEmpty (NonEmpty)
import GHC.Exts
import qualified GHC.Exts as IsList

instance Memoizable a => Memoizable [a]

instance Memoizable a => Memoizable (NonEmpty a)

newtype AsList t = AsList {forall t. AsList t -> t
unAsList :: t}

instance (IsList t, Memoizable (IsList.Item t)) => Memoizable (AsList t) where
  memoize :: forall b. (AsList t -> b) -> AsList t -> b
memoize AsList t -> b
f = forall a b. Memoizable a => (a -> b) -> a -> b
memoize (AsList t -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> AsList t
AsList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l. IsList l => [Item l] -> l
IsList.fromList) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l. IsList l => l -> [Item l]
IsList.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. AsList t -> t
unAsList