Presently I am working my way through Edwin Brady's "Type-Driven Development with Idris" text. Needless to mention, the text lists code for both SplitList and splitList (cover function).However, I wonder if the cover function given in the text could be simplified to the one that I produce below - which doesn't work as intended. Could someone please let me know why my splitList doesn't work? The error message that I receive is produced further below. Many thanks.
data SplitList : List ty -> Type where
Null : SplitList [ ]
Singleton : SplitList [x]
Pair : (lhs: List ty) -> (rhs: List ty) -> SplitList (lhs ++ rhs)
splitList : (xs: List ty) -> SplitList xs
splitList [ ] = Null
splitList [x] = Singleton
splitList xs =
let
mid = div (List.length xs) 2
lhs = List.take mid xs
rhs = List.drop mid xs
in
Pair lhs rhs
Error Message:
Type checking ./foo.idr foo.idr:53:11: When checking right hand side of splitList with expected type SplitList xs
Type mismatch between SplitList (lhs ++ rhs) (Type of Pair lhs rhs) and SplitList xs (Expected type)
Specifically: Type mismatch between lhs ++ rhs and xs Holes: Main.splitList