<commit_before>{-# LANGUAGE MultiParamTypeClasses, 
             FlexibleInstances, 
             FlexibleContexts, 
             UndecidableInstances #-} 

module Obsidian.GCDObsidian.Array ((!)
                                  , namedArray
                                  , indexArray
                                  , toLL
                                  , fromLL
                                  , LLArray(..)
                                  , OArray
                                  , Array(..)
                                  , staticLength 
                                  , dynamicLength 
                                  , llIndex  
                                  , len )where 


import Obsidian.GCDObsidian.Elem
import Obsidian.GCDObsidian.Tuple
import Obsidian.GCDObsidian.Exp 

import Data.List
import Data.Word

------------------------------------------------------------------------------
-- Arrays!


type Dynamic = Bool 

data Array a = Array (Exp Word32 -> a) Word32 

namedArray name n = Array (\ix -> index name ix) n 
indexArray n      = Array (\ix -> ix) n 


data DArray a = DArray (Exp Word32 -> a) (Exp Word32) Word32
data LLArray a = LLArray (Exp Word32 -> Exp a) (Exp Word32) Word32 Dynamic 


class OArray a e  where 
  toLL :: a (Exp e) -> LLArray e 
  fromLL :: LLArray e -> a (Exp e) 
    
instance OArray Array e where   
  toLL (Array ixf n) = LLArray ixf undefined n False
  fromLL (LLArray ixf _ n False) = Array ixf n 

class Indexible a e where 
  access :: a e -> Exp Word32 -> e 
  
instance Indexible Array a where
  access (Array ixf _) ix = ixf ix
--instance Indexible LLArray a where 
--  access (LLArray ixf _ _ _) ix = ixf ix 
instance Indexible DArray a where 
  access (DArray ixf _ _) ix = ixf ix 

len :: Array a -> Word32
len (Array _ n) = n 

-- ixf (LLArray f _ _ _ ) = f 

staticLength :: LLArray a -> Word32
staticLength (LLArray _ _ n _) = n 

dynamicLength :: LLArray a -> Exp Word32
dynamicLength (LLArray _ e _ _) = e<commit_msg>experimenting with Pushy arrays<commit_after>{-# LANGUAGE MultiParamTypeClasses, 
             FlexibleInstances, 
             FlexibleContexts, 
             UndecidableInstances, 
             RankNTypes, 
             GADTs #-} 

module Obsidian.GCDObsidian.Array ((!)
                                  , namedArray
                                  , indexArray
                                  , toLL
                                  , fromLL
                                  , LLArray(..)
                                  , OArray
                                  , Array(..)
                                  , staticLength 
                                  , dynamicLength 
                                  , llIndex  
                                  , len )where 


import Obsidian.GCDObsidian.Elem
import Obsidian.GCDObsidian.Tuple
import Obsidian.GCDObsidian.Exp 

import Data.List
import Data.Word

------------------------------------------------------------------------------
-- Arrays!


type Dynamic = Bool 

data Array a = Array (Exp Word32 -> a) Word32 


-- PUSHY ARRAYS 
data ArrayP a = ArrayP ((Exp Word32 -> (a -> Program)) -> Program) Word32

------------------------------------------------------------------------------

revP :: ArrayP a -> ArrayP a 
revP (ArrayP h n) = ArrayP (revHelp (\ix -> (fromIntegral (n-1)) - ix) h) n 
  where 
    revHelp f p = \func -> p (\i -> func (f i))
    
    
concP :: ArrayP a -> ArrayP a -> ArrayP a     
concP (ArrayP f n1) (ArrayP g n2) = 
  ArrayP (\func -> ProgramSeq ( f func )
                              ( g (\i -> func (fromIntegral n1 + i))))
                       (n1+n2)
  
 

------------------------------------------------------------------------------ 
-- Scalars for now. Learn how to loosen that demand
data Program where 
  Assign :: forall a. Scalar a => Name -> Data Word32 -> a -> Program 
  ProgramSeq :: Program  -> Program  -> Program 

  

namedArray name n = Array (\ix -> index name ix) n 
indexArray n      = Array (\ix -> ix) n 


data DArray a = DArray (Exp Word32 -> a) (Exp Word32) Word32

data LLArray a = LLArray (Exp Word32 ->Exp a) (Exp Word32) Word32 Dynamic 


class OArray a e  where 
  toLL :: a (Exp e) -> LLArray e 
  fromLL :: LLArray e -> a (Exp e) 
    
instance OArray Array e where   
  toLL (Array ixf n) = LLArray ixf undefined n False
  fromLL (LLArray ixf _ n False) = Array ixf n 

class Indexible a e where 
  access :: a e -> Exp Word32 -> e 
  
instance Indexible Array a where
  access (Array ixf _) ix = ixf ix
--instance Indexible LLArray a where 
--  access (LLArray ixf _ _ _) ix = ixf ix 
instance Indexible DArray a where 
  access (DArray ixf _ _) ix = ixf ix 

len :: Array a -> Word32
len (Array _ n) = n 

-- ixf (LLArray f _ _ _ ) = f 

staticLength :: LLArray a -> Word32
staticLength (LLArray _ _ n _) = n 

dynamicLength :: LLArray a -> Exp Word32
dynamicLength (LLArray _ e _ _) = e
{'fraction_non_alphanumeric': 0.1416700445885691, 'fraction_numerical': 0.012160518848804215, 'mean_word_length': 1.2648003671408903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 23, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3075730', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1348, 'n_words': 477}