11 | -----------
12 | -- NATS ---
13 | -----------
15 | ||| Natural numbers: unbounded, unsigned integers which can be pattern matched.
18 | ||| Zero.
19 | Z
25 | -- This is used in the compiler as an efficient substitute for integerToNat.
40 | -- %builtin IntegerToNatural Prelude.Types.integerToNat
42 | -- Define separately so we can spot the name when optimising Nats
43 | ||| Add two natural numbers.
44 | ||| @ x the number to case-split on
45 | ||| @ y the other number
51 | ||| Subtract natural numbers.
52 | ||| If the second number is larger than the first, return 0.
59 | ||| Multiply natural numbers.
72 | -- used for nat hack
83 | -- used for nat hack
99 | -- integer (+) may be non-linear in second
100 | -- argument
102 | -- %builtin NaturalToInteger Prelude.Types.natToInteger
104 | ||| Counts the number of elements that satisfy a predicate.
109 | -----------
110 | -- PAIRS --
111 | -----------
113 | %inline
118 | %inline
125 | %inline
130 | %inline
135 | %inline
142 | %inline
147 | %inline
153 | %inline
158 | -----------
159 | -- MAYBE --
160 | -----------
162 | ||| An optional value. This can be used to represent the possibility of
163 | ||| failure, where a function may return a value, or not.
166 | ||| No value stored
169 | ||| A value of type `ty` is stored
185 | ||| Execute an applicative expression when the Maybe is Just
250 | -----------------
251 | -- EQUIVALENCE --
252 | -----------------
260 | ---------
261 | -- DEC --
262 | ---------
264 | ||| Decidability. A decidable property either holds or is a contradiction.
267 | ||| The case where the property holds.
268 | ||| @ prf the proof
271 | ||| The case where the property holding would be a contradiction.
272 | ||| @ contra a demonstration that prop would be a contradiction
283 | ------------
284 | -- EITHER --
285 | ------------
287 | ||| A sum type.
290 | ||| One possibility of the sum, conventionally used to represent errors.
293 | ||| The other possibility, conventionally used to represent success.
299 | export
304 | export
309 | ||| Simply-typed eliminator for Either.
310 | ||| @ f the action to take on Left
311 | ||| @ g the action to take on Right
312 | ||| @ e the sum to analyze
331 | %inline
337 | %inline
343 | %inline
354 | %inline
360 | %inline
386 | -----------
387 | -- LISTS --
388 | -----------
411 | ||| 'fish': Action of lists on snoc-lists
417 | ||| 'chips': Action of snoc-lists on lists
433 | ||| Filters a snoc-list according to a simple classifying function
439 | ||| Apply a partial function to the elements of a list, keeping the ones at which
440 | ||| it is defined.
448 | ||| Reverse the second snoclist, prepending its elements to the first.
454 | ||| Reverses the given list.
459 | ||| Tail-recursive append. Uses of (++) are automatically transformed to
460 | ||| this. The only reason this is exported is that the proof of equivalence
461 | ||| lives in a different module.
466 | -- Always use tailRecAppend at runtime. Data.SnocList.tailRecAppendIsAppend
467 | -- proves these are equivalent.
470 | ||| Returns the first argument plus the length of the second.
476 | ||| `length` implementation that uses tail recursion. Exported so
477 | ||| lengthTRIsLength can see it.
482 | -- Data.List.lengthTRIsLength proves these are equivalent.
485 | ||| Utility for implementing `mapMaybeTR`
493 | ||| Tail recursive version of `mapMaybe`. This is automatically used
494 | ||| at runtime due to a `transform` rule.
499 | -- Data.List.mapMaybeTRIsMapMaybe proves these are equivalent.
502 | ||| Utility for implementing `filterTR`
510 | ||| Tail recursive version of `filter`. This is automatically used
511 | ||| at runtime due to a `transform` rule.
516 | -- Data.List.listTRIsList proves these are equivalent.
521 | ||| Concatenate one list with another.
527 | ||| Returns the length of the list.
533 | ||| Applied to a predicate and a list, returns the list of those elements that
534 | ||| satisfy the predicate.
543 | ||| Apply a partial function to the elements of a list, keeping the ones at which it is defined.
552 | ||| Reverse the second list, prepending its elements to the first.
558 | ||| Reverses the given list.
563 | ||| Tail-recursive append. Uses of (++) are automatically transformed to
564 | ||| this. The only reason this is exported is that the proof of equivalence
565 | ||| lives in a different module.
570 | -- Always use tailRecAppend at runtime. Data.List.tailRecAppendIsAppend
571 | -- proves these are equivalent.
574 | ||| Returns the first argument plus the length of the second.
580 | ||| `length` implementation that uses tail recursion. Exported so
581 | ||| lengthTRIsLength can see it.
586 | -- Data.List.lengthTRIsLength proves these are equivalent.
594 | ||| Utility for implementing `mapTR`
600 | ||| Tail recursive version of `map`. This is automatically used
601 | ||| at runtime due to a `transform` rule.
606 | -- Data.List.mapTRIsMap proves these are equivalent.
609 | ||| Utility for implementing `mapMaybeTR`
617 | ||| Tail recursive version of `mapMaybe`. This is automatically used
618 | ||| at runtime due to a `transform` rule.
623 | -- Data.List.mapMaybeTRIsMapMaybe proves these are equivalent.
626 | ||| Utility for implementing `filterTR`
634 | ||| Tail recursive version of `filter`. This is automatically used
635 | ||| at runtime due to a `transform` rule.
640 | -- Data.List.listTRIsList proves these are equivalent.
675 | -- tail recursive O(n) implementation of `(>>=)` for `List`
715 | -- This works quickly because when string-concat builds the result, it allocates
716 | -- enough room in advance so there's only one allocation, rather than lots!
717 | --
718 | -- Like fastUnpack, this function won't reduce at compile time.
719 | -- If you need to concatenate strings at compile time, use Prelude.concat.
720 | %foreign
721 | "scheme:string-concat"
722 | "RefC:fastConcat"
723 | "javascript:lambda:(xs)=>__prim_idris2js_array(xs).join('')"
724 | export
729 | -- The same for concatMap: Foldable List's foldMap is a left fold, so over a
730 | -- list the String and List monoids copy their accumulator at every step.
734 | ||| Check if something is a member of a list using a custom comparison.
739 | ||| Check if something is a member of a list using the default Boolean equality.
744 | ||| Lookup a value at a given position
745 | export
751 | -------------
752 | -- STREAMS --
753 | -------------
756 | ||| An infinite stream.
767 | ||| The first element of an infinite stream.
772 | ||| All but the first element.
777 | ||| Take precisely n elements from the stream.
778 | ||| @ n how many elements to take
779 | ||| @ xs the stream
785 | -------------
786 | -- STRINGS --
787 | -------------
794 | ||| Returns the length of the string.
795 | |||
796 | ||| ```idris example
797 | ||| length ""
798 | ||| ```
799 | ||| ```idris example
800 | ||| length "ABC"
801 | ||| ```
806 | ||| Reverses the elements within a string.
807 | |||
808 | ||| ```idris example
809 | ||| reverse "ABC"
810 | ||| ```
811 | ||| ```idris example
812 | ||| reverse ""
813 | ||| ```
818 | ||| Returns a substring of a given string
819 | |||
820 | ||| @ index The (zero based) index of the string to extract. If this is beyond
821 | ||| the end of the string, the function returns the empty string.
822 | ||| @ len The desired length of the substring. Truncated if this exceeds the
823 | ||| length of the input
824 | ||| @ subject The string to return a portion of
831 | subj
834 | ||| Adds a character to the front of the specified string.
835 | |||
836 | ||| ```idris example
837 | ||| strCons 'A' "B"
838 | ||| ```
839 | ||| ```idris example
840 | ||| strCons 'A' ""
841 | ||| ```
851 | ||| Turns a list of characters into a string.
857 | %foreign
858 | "scheme:string-pack"
859 | "RefC:fastPack"
860 | "javascript:lambda:(xs)=>__prim_idris2js_array(xs).join('')"
861 | export
864 | -- always use 'fastPack' at run time
867 | ||| Turns a string into a list of characters.
868 | |||
869 | ||| ```idris example
870 | ||| unpack "ABC"
871 | ||| ```
875 | where
882 | -- This function runs fast when compiled but won't compute at compile time.
883 | -- If you need to unpack strings at compile time, use Prelude.unpack.
884 | %foreign
885 | "scheme:string-unpack"
886 | "RefC:fastUnpack"
887 | "javascript:lambda:(str)=>__prim_js2idris_array(Array.from(str))"
888 | export
891 | -- always use 'fastPack' at run time
902 | ----------------
903 | -- CHARACTERS --
904 | ----------------
906 | ||| Returns true if the character is in the range [A-Z].
911 | ||| Returns true if the character is in the range [a-z].
916 | ||| Returns true if the character is in the ranges [A-Z][a-z].
921 | ||| Returns true if the character is in the range [0-9].
926 | ||| Returns true if the character is in the ranges [A-Z][a-z][0-9].
931 | ||| Returns true if the character is a whitespace character.
943 | ||| Returns true if the character represents a new line.
950 | ||| Convert a letter to the corresponding upper-case letter, if any.
951 | ||| Non-letters are ignored.
959 | ||| Convert a letter to the corresponding lower-case letter, if any.
960 | ||| Non-letters are ignored.
968 | ||| Returns true if the character is a hexadecimal digit i.e. in the range
969 | ||| [0-9][a-f][A-F].
974 | ||| Returns true if the character is an octal digit.
979 | ||| Returns true if the character is a control character.
986 | ||| Convert the number to its backend dependent (usually Unicode) Char
987 | ||| equivalent.
992 | ||| Return the backend dependent (usually Unicode) numerical equivalent of the Char.
997 | -----------------------
998 | -- DOUBLE PRIMITIVES --
999 | -----------------------
1069 | ------------
1070 | -- RANGES --
1071 | ------------
1073 | -- These functions are here to support the range syntax:
1074 | -- range expressions like `[a..b]` are desugared to `rangeFromXXX` calls.
1081 | covering
1089 | covering
1105 | -- Idris 1 went to great lengths to prove that these were total. I don't really
1106 | -- think it's worth going to those lengths! Let's keep it simple and assert.
1132 | -- Go down
1134 | -- Meaningless
1136 | -- Go up