How to evaluate this recursive function in Idris interactive mode?

Immersed in Idris, I tried to connect this Haskell function to Idris. I think I succeeded with this code ...

windowl : Nat -> List a -> List (List a)
windowl size = loop
  where
    loop xs = case List.splitAt size xs of
      (ys, []) => if length ys == size then [ys] else []
      (ys, _) => ys :: loop (drop 1 xs)

However, when I call it in an interactive idris, it seems that only the first function call is evaluated, the next step in recursion is not. This is what I get on the console.

*hello> windowl 2 [1,2,3,4,5]
[1, 2] :: Main.windowl, loop Integer 2 [2, 3, 4, 5] : List (List Integer)

Can someone enlighten me about what is happening and how can I fully appreciate the function?

+4
source share
1 answer

As explained in the manual :

[] , , ,... []... REPL, , .

, windowl , , assert_smaller construction:

total
windowl : Nat -> List a -> List (List a)
windowl size = loop
  where
    loop : List a -> List (List a)
    loop xs = case List.splitAt size xs of
      (ys, []) => if length ys == size then [ys] else []
      (ys, _) => ys :: loop (assert_smaller xs $ drop 1 xs)

loop, :

total
windowl : Nat -> List a -> List (List a)
windowl size = loop
  where
    loop : List a -> List (List a)
    loop [] = []
    loop xs@(x :: xs') = case List.splitAt size xs of
      (ys, []) => if length ys == size then [ys] else []
      (ys, _) => ys :: loop xs'

, , hardcoded drop 1 , . .

REPL :

λΠ> windowl 2 [1,2,3,4,5]
[[1, 2], [2, 3], [3, 4], [4, 5]] : List (List Integer)
+4

Source: https://habr.com/ru/post/1677578/


All Articles