Skip to content

Commit

Permalink
Merge pull request #221 from gelisam/list-append
Browse files Browse the repository at this point in the history
list-append
  • Loading branch information
gelisam authored Oct 15, 2023
2 parents 6bb365c + a660aad commit 9cc4dab
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 31 deletions.
8 changes: 8 additions & 0 deletions examples/list-test.golden
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
10 : Integer
(:: 3 (:: 3 (:: 3 (:: 4 (nil))))) : (List Integer)
(:: 1 (:: 2 (:: 3 (nil)))) : (List Integer)
(:: 1 (:: 2 (:: 3 (:: 4 (nil))))) : (List Integer)
(:: 3 (:: 2 (:: 1 (nil)))) : (List Integer)
(:: #[list-test.kl:26.19-26.20]<a>
(:: #[list-test.kl:26.21-26.22]<b>
(:: #[list-test.kl:26.23-26.24]<c> (nil)))) : (List Syntax)
#[list-test.kl:29.34-29.38]<(a b c)> : Syntax
26 changes: 25 additions & 1 deletion examples/list-test.kl
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
#lang "prelude.kl"

-- These examples are here rather than in "list.kl" so that the resulting
-- values are tracked by our test suite, which only covers the "examples"
-- folder, not "stdlib".

(import "list.kl")

(example (reverse (list 1 2 3)))
(example
(foldr + 0 (list 1 2 3 4)))

(example
(map string-length (list "foo" "bar" "baz" "quux")))

(example
(filter (lambda (x) (< x 10))
(list 1 11 111 2 22 222 3 33 333)))

(example
(snoc (list 1 2 3) 4))

(example
(reverse (list 1 2 3)))

(example
(syntax->list '(a b c)))

(example
(list->syntax (list 'a 'b 'c) 'here))
4 changes: 2 additions & 2 deletions repl/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module Main where
import Control.Exception
import Control.Lens hiding (argument)
import Control.Monad
import Control.Monad.Except
import Control.Monad.Reader
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Except

import Data.Foldable (for_)
import Data.IORef
Expand Down
7 changes: 5 additions & 2 deletions src/Evaluator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
module Evaluator where

import Control.Lens hiding (List, elements)
import Control.Monad.Except
import Control.Monad.Reader
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.Except (MonadError(throwError))
import Control.Monad.Reader (MonadReader(ask, local))
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Reader (ReaderT)
import Data.Text (Text)
import qualified Data.Text as T

Expand Down
10 changes: 7 additions & 3 deletions src/Expander.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ module Expander (
import Control.Applicative
import Control.Lens hiding (List, children)
import Control.Monad
import Control.Monad.Except
import Control.Monad.Reader
import Control.Monad.State.Strict
import Control.Monad.IO.Class (MonadIO(liftIO))
import Control.Monad.Except (MonadError(catchError, throwError))
import Control.Monad.Reader (MonadReader(local))
import Control.Monad.Trans.Class (MonadTrans(lift))
import Control.Monad.Trans.Except (runExceptT)
import Control.Monad.Trans.Reader (runReaderT)
import Control.Monad.Trans.State.Strict (StateT, execStateT, modify', runStateT)
import Data.Foldable
import Data.Function (on)
import Data.List (nub)
Expand Down
7 changes: 5 additions & 2 deletions src/Expander/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,11 @@ import Control.Applicative
import Control.Arrow
import Control.Lens
import Control.Monad
import Control.Monad.Except
import Control.Monad.Reader
import Control.Monad.IO.Class (MonadIO(liftIO))
import Control.Monad.Except (MonadError(throwError))
import Control.Monad.Reader (MonadReader(ask, local), asks)
import Control.Monad.Trans.Except (ExceptT, runExceptT)
import Control.Monad.Trans.Reader (ReaderT, runReaderT)
import Data.Foldable
import Data.IORef
import Data.HashMap.Strict (HashMap)
Expand Down
21 changes: 0 additions & 21 deletions stdlib/list.kl
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,4 @@
[(cons x xs)
(pure (quasiquote/loc more (:: ,x ,(cons-list-syntax 'list xs xs))))])]))]))

(example
(foldr + 0 (list 1 2 3 4)))

(example
(map string-length (list "foo" "bar" "baz" "quux")))

(example
(filter (< 10) (list 1 11 111 2 22 222 3 33 333)))

(example
(snoc (list 1 2 3) 4))

(example
(reverse (list 1 2 3)))

(example
(syntax->list '(a b c)))

(example
(list->syntax (list 'a 'b 'c) 'here))

(export List nil :: foldr map filter snoc reverse syntax->list list->syntax list)

0 comments on commit 9cc4dab

Please sign in to comment.