module UVMHS.Core.Data.Sequence where

import UVMHS.Core.Init
import UVMHS.Core.Classes

import UVMHS.Core.Data.Iter
import UVMHS.Core.Data.Stream ()
import UVMHS.Core.Data.String

import qualified Prelude as HS
import qualified Data.Foldable as HS
import qualified Data.Sequence as Sequence

instance Null (𝑄 a) where 
  null :: 𝑄 a
null = 𝑄 a
forall a. 𝑄 a

instance Append (𝑄 a) where 
  ⧺ :: 𝑄 a -> 𝑄 a -> 𝑄 a
(⧺) = 𝑄 a -> 𝑄 a -> 𝑄 a
forall a. 𝑄 a -> 𝑄 a -> 𝑄 a
append𝑄
instance Monoid (𝑄 a)
instance Single a (𝑄 a) where 
  single :: a -> 𝑄 a
single = a -> 𝑄 a
forall a. a -> 𝑄 a
single𝑄

instance Functor 𝑄 where 
  map :: forall a b. (a -> b) -> 𝑄 a -> 𝑄 b
map = (a -> b) -> 𝑄 a -> 𝑄 b
forall a b. (a -> b) -> 𝑄 a -> 𝑄 b
map𝑄
instance Return 𝑄 where 
  return :: forall a. a -> 𝑄 a
return = a -> 𝑄 a
forall a t. Single a t => a -> t
single
instance Bind 𝑄 where 
  ≫= :: forall a b. 𝑄 a -> (a -> 𝑄 b) -> 𝑄 b
(≫=) = 𝑄 a -> (a -> 𝑄 b) -> 𝑄 b
forall a b. 𝑄 a -> (a -> 𝑄 b) -> 𝑄 b
bind𝑄
instance Monad 𝑄

instance ToIter a (𝑄 a) where 
  iter :: 𝑄 a -> 𝐼 a
iter = 𝑄 a -> 𝐼 a
forall a. 𝑄 a -> 𝐼 a
iter𝑄

instance (Show a)  Show (𝑄 a) where 
  show :: 𝑄 a -> String
show = 𝕊 -> String
tohsChars (𝕊 -> String) -> (𝑄 a -> 𝕊) -> 𝑄 a -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕊 -> 𝕊 -> 𝕊 -> (a -> 𝕊) -> 𝑄 a -> 𝕊
forall a t. ToIter a t => 𝕊 -> 𝕊 -> 𝕊 -> (a -> 𝕊) -> t -> 𝕊
showCollection 𝕊
"[" 𝕊
"]" 𝕊
"," a -> 𝕊
forall a. Show a => a -> 𝕊
show𝕊

  𝑄 a
qø :: forall a. 𝑄 a
 = Seq a -> 𝑄 a
forall a. Seq a -> 𝑄 a
𝑄 Seq a
forall a. Seq a
Sequence.empty

cons𝑄  a  𝑄 a  𝑄 a
cons𝑄 :: forall a. a -> 𝑄 a -> 𝑄 a
cons𝑄 a
x 𝑄 a
xs = Seq a -> 𝑄 a
forall a. Seq a -> 𝑄 a
𝑄 (Seq a -> 𝑄 a) -> Seq a -> 𝑄 a
forall a b. (a -> b) -> a -> b
$ a
x a -> Seq a -> Seq a
forall a. a -> Seq a -> Seq a
Sequence.:<| 𝑄 a -> Seq a
forall a. 𝑄 a -> Seq a
un𝑄 𝑄 a
xs

uncons𝑄  𝑄 a  𝑂 (a  𝑄 a)
uncons𝑄 :: forall a. 𝑄 a -> 𝑂 (a ∧ 𝑄 a)
uncons𝑄 𝑄 a
xs = case Seq a -> ViewL a
forall a. Seq a -> ViewL a
Sequence.viewl (Seq a -> ViewL a) -> Seq a -> ViewL a
forall a b. (a -> b) -> a -> b
$ 𝑄 a -> Seq a
forall a. 𝑄 a -> Seq a
un𝑄 𝑄 a
xs of
  ViewL a
Sequence.EmptyL  𝑂 (a ∧ 𝑄 a)
forall a. 𝑂 a
None
  a
x Sequence.:< Seq a
xs'  (a ∧ 𝑄 a) -> 𝑂 (a ∧ 𝑄 a)
forall a. a -> 𝑂 a
Some ((a ∧ 𝑄 a) -> 𝑂 (a ∧ 𝑄 a)) -> (a ∧ 𝑄 a) -> 𝑂 (a ∧ 𝑄 a)
forall a b. (a -> b) -> a -> b
$ a
x a -> 𝑄 a -> a ∧ 𝑄 a
forall a b. a -> b -> a ∧ b
:* Seq a -> 𝑄 a
forall a. Seq a -> 𝑄 a
𝑄 Seq a
xs'

snoc𝑄  𝑄 a  a  𝑄 a
snoc𝑄 :: forall a. 𝑄 a -> a -> 𝑄 a
snoc𝑄 𝑄 a
xs a
x = Seq a -> 𝑄 a
forall a. Seq a -> 𝑄 a
𝑄 (Seq a -> 𝑄 a) -> Seq a -> 𝑄 a
forall a b. (a -> b) -> a -> b
$ 𝑄 a -> Seq a
forall a. 𝑄 a -> Seq a
un𝑄 𝑄 a
xs Seq a -> a -> Seq a
forall a. Seq a -> a -> Seq a
Sequence.:|> a
x

unsnoc𝑄  𝑄 a  𝑂 (𝑄 a  a)
unsnoc𝑄 :: forall a. 𝑄 a -> 𝑂 (𝑄 a ∧ a)
unsnoc𝑄 𝑄 a
xs = case Seq a -> ViewR a
forall a. Seq a -> ViewR a
Sequence.viewr (Seq a -> ViewR a) -> Seq a -> ViewR a
forall a b. (a -> b) -> a -> b
$ 𝑄 a -> Seq a
forall a. 𝑄 a -> Seq a
un𝑄 𝑄 a
xs of
  ViewR a
Sequence.EmptyR  𝑂 (𝑄 a ∧ a)
forall a. 𝑂 a
None
  Seq a
xs' Sequence.:> a
x  (𝑄 a ∧ a) -> 𝑂 (𝑄 a ∧ a)
forall a. a -> 𝑂 a
Some ((𝑄 a ∧ a) -> 𝑂 (𝑄 a ∧ a)) -> (𝑄 a ∧ a) -> 𝑂 (𝑄 a ∧ a)
forall a b. (a -> b) -> a -> b
$ Seq a -> 𝑄 a
forall a. Seq a -> 𝑄 a
𝑄 Seq a
xs' 𝑄 a -> a -> 𝑄 a ∧ a
forall a b. a -> b -> a ∧ b
:* a
x

single𝑄  a  𝑄 a
single𝑄 :: forall a. a -> 𝑄 a
single𝑄 = Seq a -> 𝑄 a
forall a. Seq a -> 𝑄 a
𝑄 (Seq a -> 𝑄 a) -> (a -> Seq a) -> a -> 𝑄 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 a -> Seq a
forall a. a -> Seq a
Sequence.singleton

append𝑄  𝑄 a  𝑄 a  𝑄 a
append𝑄 :: forall a. 𝑄 a -> 𝑄 a -> 𝑄 a
append𝑄 𝑄 a
xs 𝑄 a
ys = Seq a -> 𝑄 a
forall a. Seq a -> 𝑄 a
𝑄 (Seq a -> 𝑄 a) -> Seq a -> 𝑄 a
forall a b. (a -> b) -> a -> b
$ 𝑄 a -> Seq a
forall a. 𝑄 a -> Seq a
un𝑄 𝑄 a
xs Seq a -> Seq a -> Seq a
forall a. Seq a -> Seq a -> Seq a
Sequence.>< 𝑄 a -> Seq a
forall a. 𝑄 a -> Seq a
un𝑄 𝑄 a
ys

map𝑄  (a  b)  𝑄 a  𝑄 b
map𝑄 :: forall a b. (a -> b) -> 𝑄 a -> 𝑄 b
map𝑄 a -> b
f = Seq b -> 𝑄 b
forall a. Seq a -> 𝑄 a
𝑄 (Seq b -> 𝑄 b) -> (Seq a -> Seq b) -> Seq a -> 𝑄 b
forall b c a. (b -> c) -> (a -> b) -> a -> c
 (a -> b) -> Seq a -> Seq b
forall a b. (a -> b) -> Seq a -> Seq b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
HS.fmap a -> b
f (Seq a -> 𝑄 b) -> (𝑄 a -> Seq a) -> 𝑄 a -> 𝑄 b
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝑄 a -> Seq a
forall a. 𝑄 a -> Seq a
un𝑄

bind𝑄  𝑄 a  (a  𝑄 b)  𝑄 b
bind𝑄 :: forall a b. 𝑄 a -> (a -> 𝑄 b) -> 𝑄 b
bind𝑄 𝑄 a
xs a -> 𝑄 b
f = Seq b -> 𝑄 b
forall a. Seq a -> 𝑄 a
𝑄 (Seq b -> 𝑄 b) -> Seq b -> 𝑄 b
forall a b. (a -> b) -> a -> b
$ 𝑄 a -> Seq a
forall a. 𝑄 a -> Seq a
un𝑄 𝑄 a
xs Seq a -> (a -> Seq b) -> Seq b
forall a b. Seq a -> (a -> Seq b) -> Seq b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
HS.>>= (𝑄 b -> Seq b
forall a. 𝑄 a -> Seq a
un𝑄 (𝑄 b -> Seq b) -> (a -> 𝑄 b) -> a -> Seq b
forall b c a. (b -> c) -> (a -> b) -> a -> c
 a -> 𝑄 b
f)

iter𝑄  𝑄 a  𝐼 a
iter𝑄 :: forall a. 𝑄 a -> 𝐼 a
iter𝑄 = [a] -> 𝐼 a
forall a. [a] -> 𝐼 a
iterLL ([a] -> 𝐼 a) -> (Seq a -> [a]) -> Seq a -> 𝐼 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 Seq a -> [a]
forall a. Seq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
HS.toList (Seq a -> 𝐼 a) -> (𝑄 a -> Seq a) -> 𝑄 a -> 𝐼 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝑄 a -> Seq a
forall a. 𝑄 a -> Seq a
un𝑄

seq𝐼  𝐼 a  𝑄 a
seq𝐼 :: forall a. 𝐼 a -> 𝑄 a
seq𝐼 = Seq a -> 𝑄 a
forall a. Seq a -> 𝑄 a
𝑄 (Seq a -> 𝑄 a) -> ([a] -> Seq a) -> [a] -> 𝑄 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 [a] -> Seq a
forall a. [a] -> Seq a
Sequence.fromList ([a] -> 𝑄 a) -> (𝐼 a -> [a]) -> 𝐼 a -> 𝑄 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝐼 a -> [a]
forall a t. ToIter a t => t -> [a]
lazyList

seq  (ToIter a t)  t  𝑄 a
seq :: forall a t. ToIter a t => t -> 𝑄 a
seq = 𝐼 a -> 𝑄 a
forall a. 𝐼 a -> 𝑄 a
seq𝐼 (𝐼 a -> 𝑄 a) -> (t -> 𝐼 a) -> t -> 𝑄 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 t -> 𝐼 a
forall a t. ToIter a t => t -> 𝐼 a
iter