Rerouted (retagged, needs approval). The tag now points at a different commit than when this version was published. The Lamdera package server serves a copy recovered from https://github.com/lue-bird/elm-typesafe-array.
What we checked: Tag 7.1.0 is still on github.com/lue-bird/elm-typesafe-array; its commit c17a96304817 is from 2021-05-03 17:31 UTC, after the version was published (2021-05-03 17:29 UTC); elm.json is byte-identical to package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one and nothing else confirms its contents.
We could not verify this copy against what was published, so the Lamdera compiler asks before using it (y/n). Without a terminal, as in CI, it stops with an error unless approved:
lamdera make --auto-approve-package-rerouting approves rerouted versions for that run,LAMDERA_AUTO_APPROVE_PACKAGE_REROUTING=1 does the same for every run in that environment,LAMDERA_CACHE=off skips the Lamdera package server altogether: packages come from package.elm-lang.org and GitHub only, as with elm, and a rerouted version then fails to download.Details · package.elm-lang.org's zip: https://github.com/lue-bird/elm-typesafe-array/zipball/7.1.0/
Knowing more about the length of an Array at compile-time to help you access elements safely.
chessBoard
|> Arr.at nat1 FirstToLast
|> Arr.at nat6 FirstToLastreturns a value, not a Maybe if chessBoard's type can promise that it contains enough elements.
A type that can hold that promise could be:
{-| 8 by 8 -}
type alias ChessBoard =
Arr (Only Nat8) (Arr (Only Nat8) Field)
type Field
= Empty
| Piece PieceKind Color
type PieceKind = Pawn | --...
type Color = Black | WhiteinitialChessBoard : ChessBoard
initialChessBoard =
let
pawnRow color =
Arr.repeat nat8 (Piece Pawn color)
firstRow color =
Arr.repeat nat8 (Piece Other color)
in
Arr.empty
|> InArr.push (firstRow White)
|> InArr.push (pawnRow White)
|> InArr.extendOnly nat4
(Arr.repeat nat4 (Arr.repeat nat8 Empty))
|> InArr.push (pawnRow Black)
|> InArr.push (firstRow Black)We know there are enough elements in initialChessBoard. You can then easily ask:
initialChessBoard
|> Arr.at nat1 FirstToLast
|> Arr.at nat6 FirstToLast
--> Piece Pawn WhiteIf you want, take a 👀 to get a feel why the used packages are useful.
nat... part, also for building the typeFirstToLast & LastToFirstelm install lue-bird/elm-linear-direction
elm install lue-bird/elm-typed-value
elm install lue-bird/elm-bounded-nat
elm install lue-bird/elm-typesafe-arrayimport LinearDirection exposing (LinearDirection(..))
import Nat exposing (Nat, Only, In, Min)
import MinNat
import InNat
import NNats exposing (..)
-- (..) is nat0 to nat160
import Typed exposing (val)
import TypeNats exposing (..)
-- (..) is Nat0 to Nat160 & Nat1Plus to Nat160Plus
import Arr exposing (Arr)
import InArr
import MinArrYou can define & use operations for Arrs with a certain amount.
first :
Arr (In (Nat1Plus orLonger) max) element
-> element
first =
Arr.at nat0 FirstToLast
biggest :
Arr (In (Nat1Plus orLonger) max) comparable
-> comparable
biggest =
Arr.foldWith FirstToLast max
first Arr.empty --> compile-time error
biggest Arr.empty --> compile-time errorArr (In (Nat1Plus orLonger) max) means what exactly?
→ It constrains the length of possible Arrs.
The types are explained in more detail in bounded-nat (but be aware that its Arg... types aren't used for Arrs!). In this example:
Arr: Array with additional type info about its lengthIn: length is within a minimum (& maximum)Nat1Plus orLonger: the minimum length is >= 1max: no maximum length or any maximum lengthtype alias TicTacToeBoard =
Arr (Only Nat3)
(Arr (Only Nat3) TicTacToeField)
type TicTacToeField =
FieldEmpty
| X
| O
initialTicTacToeBoard : TicTacToeBoard
initialTicTacToeBoard =
Arr.repeat nat3
(Arr.repeat nat3 FieldEmpty)-- the max tag count should be 53
tag : Arr (In min Nat53) Tag -> a -> Tagged a
tag tags toTag = --...
tag (Arr.from3 "fun" "easy" "fresh")
--> valid
tag (Arr.repeat nat100 EmptyTag)
--> compile-time errorNow take a look at modules like Arr to get started!