Recursions on more complicated datatypes
Definition of the datatype list is recursive. So,when we define a function for such datatypes, it comes naturally to define the function recursively.
length' :: forall a . [a] -> Integer
length' [] = 0
length' [x|xs] = 1 + length xs
> length' "hamler"
6
当前内容版权归 hamler-lang 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 hamler-lang .