<commit_before>module Jhc.Array(
    Array__(),
    AT(),
    seqAT__,
    doneAT__,
    newAT__,
    writeAT__,
    unsafeAt__,
    newArray
    where

import Jhc.IO(dependingOn)

-- The internal array type
data Array__ a

-- the built-in array quasi-monad
newtype AT a = AT (Array__ a -> Array__ a)

seqAT__ :: AT a -> AT a -> AT a
seqAT__ (AT a1) (AT a2) = AT $ \a -> a2 (a1 a)

doneAT__ :: AT a
doneAT__ = AT id

newAT__ :: Int -> AT a -> Array__ a
newAT__ n (AT a1) = a1 (prim_newAT__ (n `dependingOn` a1))

writeAT__ :: Int -> a -> AT a
writeAT__ i x = AT $ \a -> prim_writeAT__ i x a

-- none of these routines have run-time checks
foreign import primitive prim_newAT__ :: Int -> Array__ a
foreign import primitive prim_writeAT__ :: Int -> a -> Array__ a -> Array__ a

-- lookup a value in an array
foreign import primitive unsafeAt__ :: Array__ a -> Int -> a


newArray :: [a] -> Array__ a
newArray xs = newAT__ (length xs) $ foldr assign doneAT__ (zip [0..] xs) where
    assign (i,v) rs = writeAT__ i v `seqAT__` rs

<commit_msg>make Jhc.Array compile, use unboxed values<commit_after>{-# OPTIONS_JHC -N #-}
module Jhc.Array(
    Array__(),
    AT(),
    seqAT__,
    doneAT__,
    newAT__,
    writeAT__,
    unsafeAt__,
    newArray
    )
    where

import Jhc.Basics
import Jhc.IO(dependingOn)
import Jhc.Int

-- The internal array type
data Array__ :: * -> #

-- the built-in array quasi-monad
newtype AT a = AT (Array__ a -> Array__ a)

seqAT__ :: AT a -> AT a -> AT a
seqAT__ (AT a1) (AT a2) = AT $ \a -> case a1 a of
    a' -> a2 a'

doneAT__ :: AT a
doneAT__ = AT (\arr -> arr)

newAT__ :: Int -> AT a -> Array__ a
newAT__ n (AT a1) = case unboxInt (n `dependingOn` a1) of
    nn -> case prim_newAT__ nn of a' -> a1 a'

writeAT__ :: Int -> a -> AT a
writeAT__ i x = case unboxInt i of i' -> prim_writeAT__ i' x

-- none of these routines have run-time checks
foreign import primitive prim_newAT__ :: Int__ -> Array__ a
foreign import primitive prim_writeAT__ :: Int__ -> a -> AT a
--foreign import primitive prim_copyAT__ :: Int__ -> Int__ -> Array__ a -> AT a

-- lookup a value in an array
foreign import primitive unsafeAt__ :: Array__ a -> Int__ -> a



--newArray :: [a] -> Array__ a
--newArray xs = newAT__ (length xs) $ foldr assign doneAT__ (zip [0..] xs) where
--    assign (i,v) rs = writeAT__ i v `seqAT__` rs

newArray :: Int -> [(Int,a)] -> Array__ a
newArray n xs = newAT__ n (foldr assign doneAT__ xs) where
        assign (i,v) rs = writeAT__ i v `seqAT__` rs


{-
newArray :: Int -> [a] -> Array__ a
newArray n xs = case unboxInt n of
    un -> newAT__ un $ f zero__ xs where
        f _ [] = doneAT__
        f n (x:xs) = case increment__ n of nn -> writeAT__ n x `seqAT__` f nn xs
-}
{'fraction_non_alphanumeric': 0.12205882352941176, 'fraction_numerical': 0.0058823529411764705, 'mean_word_length': 2.70708446866485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3267597', 'n_tokens_mistral': 1010, 'n_tokens_neox': 983, 'n_words': 386}