リストの最後まで行ったら先頭にもどるタイプのデータは、つぎのように実装できる。

type Rot a = ([a], [a])

uncons :: Rot a -> (a, Rot a)

uncons (xs, []) = uncons (xs, xs)

uncons (xs, x : xs') = (x, (xs, xs'))

Reply to this note

Please Login to reply.

Discussion

No replies yet.