mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-17 08:27:45 +03:00
25839de02d
Extends Carp's support for type reflection by returning types for values as well as bindings. `type` now also returns a valid Carp expression/s-expression and so its output can be used as input to dynamic functions and macros (prior to this commit, `type` printed the type to the REPL but did not return a meaningful expression in Carp). Here are a few illustrations of the behavior: ``` (def x 1) ;; type now returns an s-expression/symbol (type x) => Int ;; It also works on values (type 1) => Int (type 2b) => Byte (type "foo") => (Ref String <StaticLifetime>) ;; It works on more complex values as well (type Maybe) => Module (type Maybe.Just) (Fn [a] (Maybe a) <StaticLifetime>) ;; reports honestly about polymorphism (type (Maybe.Nothing)) => (Maybe a) (type (Pair.init 1 2)) => (Pair Int Int) ;; What about the type of types? (type (type 2)) => Type ;; Or the type of types of types? (type (type (type 2))) => () ;; One more time! (type (type (type (type 2)))) => () ;; so, () is the fixpoint of type, and is reached after two applications (type zero) ;; the type of an interface is all of its implementations => (((Fn [] (Array a) <StaticLifetime>) (Fn [] Bool <StaticLifetime>) (Fn [] Byte <StaticLifetime>) (Fn [] Char <StaticLifetime>) (Fn [] Double <StaticLifetime>) (Fn [] Float <StaticLifetime>) (Fn [] Int <StaticLifetime>) (Fn [] Int16 <StaticLifetime>) (Fn [] Int32 <StaticLifetime>) (Fn [] Int64 <StaticLifetime>) (Fn [] Int8 <StaticLifetime>) (Fn [] Long <StaticLifetime>) (Fn [] (Maybe a) <StaticLifetime>) (Fn [] (Pair a b) <StaticLifetime>) (Fn [] (Quadruple a b c d) <StaticLifetime>) (Fn [] String <StaticLifetime>) (Fn [] (Triple a b c) <StaticLifetime>) (Fn [] Uint16 <StaticLifetime>) (Fn [] Uint32 <StaticLifetime>) (Fn [] Uint64 <StaticLifetime>) (Fn [] Uint8 <StaticLifetime>))) ``` As shown in the example above, this change also includes a cosmetic update to the representation of lifetime variables, which are surrounded in <> to distinguish them from type variables. This commit also adds a new `kind` primitive that reports on the kind of a binding or value: ``` (def x 3) (kind x) => Base (kind 2) => Base (kind Maybe.Just) => Higher (kind (Maybe.Just 2)) => Higher ``` `kind` and `type` both support interactive development in the repl, for example, a user can rely on `kind` to check the kind of a type they plan on using in an interface that demands a higher-kinded argument. Likewise, they both also support developing macros based on type information.
118 lines
3.6 KiB
Plaintext
118 lines
3.6 KiB
Plaintext
name: CarpHask
|
|
version: 0.3.0.0
|
|
-- synopsis:
|
|
-- description:
|
|
homepage: https://github.com/eriksvedang/Carp
|
|
license: Apache-2.0
|
|
license-file: LICENSE
|
|
author: Erik Svedäng
|
|
maintainer: erik.svedang@gmail.com
|
|
copyright: Erik Svedäng
|
|
category: General
|
|
build-type: Simple
|
|
extra-source-files: README.md
|
|
cabal-version: >=1.10
|
|
|
|
library
|
|
hs-source-dirs: src
|
|
exposed-modules: Info,
|
|
Obj,
|
|
Meta,
|
|
Project,
|
|
Parsing,
|
|
Infer,
|
|
Emit,
|
|
ColorText,
|
|
Constraints,
|
|
Deftype,
|
|
Sumtypes,
|
|
SumtypeCase,
|
|
Commands,
|
|
Template,
|
|
ToTemplate,
|
|
SymPath,
|
|
Types,
|
|
TypesToC,
|
|
Util,
|
|
Eval,
|
|
TypeError,
|
|
InitialTypes,
|
|
AssignTypes,
|
|
GenerateConstraints,
|
|
Polymorphism,
|
|
Concretize,
|
|
ArrayTemplates,
|
|
StaticArrayTemplates,
|
|
Expand,
|
|
Scoring,
|
|
Lookup,
|
|
Qualify,
|
|
Repl,
|
|
StartingEnv,
|
|
RenderDocs,
|
|
StructUtils,
|
|
Path,
|
|
Interfaces,
|
|
Primitives,
|
|
Validate,
|
|
Reify
|
|
|
|
build-depends: base >= 4.7 && < 5
|
|
, parsec == 3.1.*
|
|
, mtl
|
|
, containers
|
|
, process
|
|
, directory
|
|
, filepath
|
|
, split
|
|
, haskeline
|
|
, blaze-html
|
|
, blaze-markup
|
|
, text
|
|
, ansi-terminal >= 0.10.3
|
|
, cmark
|
|
, edit-distance
|
|
|
|
default-language: Haskell2010
|
|
|
|
executable carp
|
|
hs-source-dirs: app
|
|
main-is: Main.hs
|
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
|
build-depends: base
|
|
, CarpHask
|
|
, containers
|
|
, directory
|
|
, filepath
|
|
, haskeline
|
|
, process
|
|
, optparse-applicative
|
|
default-language: Haskell2010
|
|
|
|
executable carp-header-parse
|
|
hs-source-dirs: headerparse
|
|
main-is: Main.hs
|
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
|
build-depends: base
|
|
, CarpHask
|
|
, containers
|
|
, directory
|
|
, parsec
|
|
, optparse-applicative
|
|
default-language: Haskell2010
|
|
|
|
test-suite CarpHask-test
|
|
type: exitcode-stdio-1.0
|
|
hs-source-dirs: test
|
|
main-is: Spec.hs
|
|
build-depends: base
|
|
, CarpHask
|
|
, HUnit
|
|
, containers
|
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
|
default-language: Haskell2010
|
|
|
|
source-repository head
|
|
type: git
|
|
location: https://github.com/carp-lang/Carp
|