>>> init [1, 2, 3] [1,2]
>>> init [1] []
>>> init [] *** Exception: Prelude.init: empty list
init :: NonEmpty a -> [a]but it was given a more complex type to provide friendlier compile time errors.
>>> init ('a' :| "bcde") "abcd" >>> init [0..5 :: Int] ... ... 'init' works with 'NonEmpty', not ordinary lists. Possible fix: Replace: [Int] With: NonEmpty Int ... However, you can use 'init' with the ordinary lists. Apply 'viaNonEmpty' function from relude: viaNonEmpty init (yourList) Note, that this will return 'Maybe [Int]' therefore it is a safe function unlike 'init' from the standard Prelude ... >>> init (Just 'a') ... ... 'init' works with 'NonEmpty Char' lists But given: Maybe Char ...
>>> prove $ \(h :: SInteger) t -> init (t ++ [h]) .== t Q.E.D. >>> prove $ \(c :: SChar) t -> init (t ++ [c]) .== t Q.E.D.
>>> inits "abc" ["","a","ab","abc"]
>>> inits [] [[]]inits is productive on infinite lists:
>>> take 5 $ inits [1..] [[],[1],[1,2],[1,2,3],[1,2,3,4]]
>>> inits1 "abc" ['a' :| "",'a' :| "b",'a' :| "bc"]
>>> inits1 [] []inits1 is productive on infinite lists:
>>> take 3 $ inits1 [1..] [1 :| [],1 :| [2],1 :| [2,3]]
>>> inits ([] :: SList Integer) [[]] :: [[SInteger]] >>> inits [1,2,3,4::SInteger] [[],[1],[1,2],[1,2,3],[1,2,3,4]] :: [[SInteger]]
length (inits xs) == 1 + length xs
>>> runTP $ initsLength @Integer Inductive lemma (strong): initsLength Step: Measure is non-negative Q.E.D. Step: 1 Q.E.D. Result: Q.E.D. [Proven] initsLength :: Ɐxs ∷ [Integer] → Bool