APL Interpreter – An implementation of APL, written in Haskell (2024)
created: June 5, 2025, 9:22 p.m. | updated: June 6, 2025, 4:15 p.m.
matchT2 :: ( MatchFn a, MatchFn b) -> MatchFn (a, b) matchT2 (fa, fb) ts = case fa ts of Nothing -> Nothing Just (a, ts') -> case fb ts' of Nothing -> Nothing Just (b, ts'') -> Just ((a, b), ts'') matchT3 :: ( MatchFn a, MatchFn b, MatchFn c) -> MatchFn (a, b, c) matchT3 (fa, fb, fc) ts = case fa ts of Nothing -> Nothing Just (a, ts') -> case fb ts' of Nothing -> Nothing Just (b, ts'') -> case fc ts'' of Nothing -> Nothing Just (c, ts''') -> Just ((a, b, c), ts''') matchT4 :: ( MatchFn a, MatchFn b, MatchFn c, MatchFn d) -> MatchFn (a, b, c, d) -- ... etc.
( =<< ) :: (a -> m b) -> m a -> m b -- (let a = (a, c); b = (b, c); m = Maybe in the definition of (=<<)) -- (=<<) :: ((a, c) -> Maybe (b, c)) -> Maybe (a, c) -> Maybe (b, c) -- let c = [Token] -- (=<<) :: ((a, [Token]) -> Maybe (b, [Token])) -> Maybe (a, [Token]) -> Maybe (b, [Token]) mchFst :: (a -> Maybe b) -> Maybe (a, c) -> Maybe (b, c) -- let c = [Token] -- mchFst :: (a -> Maybe b) -> Maybe (a, [Token]) -> Maybe (b, [Token]) -- (=<<) :: ((a, [Token]) -> Maybe (b, [Token])) -> Maybe (a, [Token]) -> Maybe (b, [Token]) -- mchFst :: (a -> Maybe b ) -> Maybe (a, [Token]) -> Maybe (b, [Token])So mchFst is just a specialized version of (=<<) that assumes that the token-list remains unchanged.
type MatchFn a = ( IdMap , [ Token ]) -> Maybe (a, [ Token ], IdMap ) mfFmap :: ( a -> b) -> MatchFn a -> MatchFn b mfFBindMaybe :: ( a -> Maybe b) -> MatchFn a -> MatchFn b mfFBindIdm :: ( IdMap -> a -> b) -> MatchFn a -> MatchFn b mfFBindIdm' :: ( IdMap -> a -> MatchFn b) -> MatchFn a -> MatchFn b mfFBindIdmMaybe :: ( IdMap -> a -> Maybe b) -> MatchFn a -> MatchFn b mfFBind :: ( a -> MatchFn b) -> MatchFn a -> MatchFn bThis isn’t a very good solution, though, as it adds a lot of boilerplate (much of which is rarely used), and it doesn’t fix the other inconveniences.
: f) pureAmbivFn :: FnInfoA -> ( Array -> Array ) -> ( Array -> Array -> Array ) -> Function pureAmbivFn ia fm fd = mkAmbivFn ia ( Identity .
RankError $ "(,): invalid axis" | x == zilde = y | y == zilde = x | (shape'' x') /= (shape'' y') = throw .
2 days, 6 hours ago: Hacker News