Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to visible type applications #27

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
- uses: actions/checkout@v2

- uses: purescript-contrib/setup-purescript@main
with:
purescript: "unstable"

- uses: actions/setup-node@v2
with:
Expand Down
98 changes: 95 additions & 3 deletions src/Data/FastVect/Common.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,40 @@ module Data.FastVect.Common
( Append
, Cons
, Drop
, DropP
, Empty
, Generate
, GenerateP
, Head
, HeadM
, Last
, Index
, IndexM
, IndexMP
, IndexModulo
, IndexModuloM
, IndexP
, Last
, MapWithTerm
, Modify
, ModifyP
, NegOne
, One
, Replicate
, ReplicateP
, Set
, SetP
, Singleton
, Snoc
, Sparse
, SplitAt
, SplitAtP
, Take
, TakeP
, Zero
, class IsVect
, term
, toInt
, toIntP
) where

import Data.Maybe (Maybe)
Expand All @@ -46,8 +56,11 @@ term :: forall (i :: Int). Proxy i
term = Proxy

-- | Convert a term to an Int
toInt :: forall (len :: Int). Reflectable len Int => Proxy len -> Int
toInt = reflectType
toIntP :: forall (len :: Int). Reflectable len Int => Proxy len -> Int
toIntP = reflectType

toInt :: forall (@len :: Int). Reflectable len Int => Int
toInt = reflectType (Proxy :: Proxy len)

-- | Create a `Vect` by replicating `len` times the given element
-- |
Expand All @@ -56,6 +69,12 @@ toInt = reflectType
-- | vect = replicate (term :: _ 300) "a"
-- | ```
type Replicate vect len elem =
Compare len NegOne GT
=> Reflectable len Int
=> elem
-> vect len elem

type ReplicateP vect len elem =
Compare len NegOne GT
=> Reflectable len Int
=> Proxy len
Expand Down Expand Up @@ -122,6 +141,15 @@ type Append vect m n m_plus_n elem =
-- | ```
type Drop :: forall k. (Int -> k -> Type) -> Int -> Int -> Int -> k -> Type
type Drop vect m n m_plus_n elem =
Add m n m_plus_n
=> Reflectable m Int
=> Compare m NegOne GT
=> Compare n NegOne GT
=> vect m_plus_n elem
-> vect n elem

type DropP :: forall k. (Int -> k -> Type) -> Int -> Int -> Int -> k -> Type
type DropP vect m n m_plus_n elem =
Add m n m_plus_n
=> Reflectable m Int
=> Compare m NegOne GT
Expand All @@ -142,6 +170,15 @@ type Drop vect m n m_plus_n elem =
-- | ```
type Take :: forall k. (Int -> k -> Type) -> Int -> Int -> Int -> k -> Type
type Take vect m n m_plus_n elem =
Add m n m_plus_n
=> Reflectable m Int
=> Compare m NegOne GT
=> Compare n NegOne GT
=> vect m_plus_n elem
-> vect m elem

type TakeP :: forall k. (Int -> k -> Type) -> Int -> Int -> Int -> k -> Type
type TakeP vect m n m_plus_n elem =
Add m n m_plus_n
=> Reflectable m Int
=> Compare m NegOne GT
Expand All @@ -160,6 +197,15 @@ type Take vect m n m_plus_n elem =
-- | newVect = modify (term :: _ 100) (append "b") vect
-- | ```
type Modify vect m n elem =
Reflectable m Int
=> Compare m NegOne GT
=> Compare n NegOne GT
=> Compare m n LT
=> (elem -> elem)
-> vect n elem
-> vect n elem

type ModifyP vect m n elem =
Reflectable m Int
=> Compare m NegOne GT
=> Compare n NegOne GT
Expand All @@ -179,6 +225,15 @@ type Modify vect m n elem =
-- | newVect = modify (term :: _ 100) "b" vect
-- | `
type Set vect m n elem =
Reflectable m Int
=> Compare m NegOne GT
=> Compare n NegOne GT
=> Compare m n LT
=> elem
-> vect n elem
-> vect n elem

type SetP vect m n elem =
Reflectable m Int
=> Compare m NegOne GT
=> Compare n NegOne GT
Expand All @@ -202,6 +257,15 @@ type Set vect m n elem =
-- | ```
type SplitAt :: forall k. (Int -> k -> Type) -> Int -> Int -> Int -> k -> Type
type SplitAt vect m n m_plus_n elem =
Add m n m_plus_n
=> Reflectable m Int
=> Compare m NegOne GT
=> Compare n NegOne GT
=> vect m_plus_n elem
-> { before :: vect m elem, after :: vect n elem }

type SplitAtP :: forall k. (Int -> k -> Type) -> Int -> Int -> Int -> k -> Type
type SplitAtP vect m n m_plus_n elem =
Add m n m_plus_n
=> Reflectable m Int
=> Compare m NegOne GT
Expand Down Expand Up @@ -243,6 +307,14 @@ type IndexModuloM vect m elem =
-- | elem = index (term :: _ 299) vect
-- | ```
type Index vect m n elem =
Reflectable m Int
=> Compare m NegOne GT
=> Compare n NegOne GT
=> Compare m n LT
=> vect n elem
-> elem

type IndexP vect m n elem =
Reflectable m Int
=> Compare m NegOne GT
=> Compare n NegOne GT
Expand All @@ -252,6 +324,14 @@ type Index vect m n elem =
-> elem

type IndexM vect m n elem =
Reflectable m Int
=> Compare m NegOne GT
=> Compare n NegOne GT
=> Compare m n LT
=> vect n elem
-> Maybe elem

type IndexMP vect m n elem =
Reflectable m Int
=> Compare m NegOne GT
=> Compare n NegOne GT
Expand Down Expand Up @@ -312,6 +392,18 @@ type Snoc vect len len_plus_1 elem =
-> vect len_plus_1 elem

type Generate vect m elem =
Reflectable m Int
=> Compare m NegOne GT
=> ( forall i
. Compare i NegOne GT
=> Compare i m LT
=> Reflectable i Int
=> Proxy i
-> elem
)
-> vect m elem

type GenerateP vect m elem =
Reflectable m Int
=> Compare m NegOne GT
=> Proxy m
Expand Down
Loading