Use heskell to construct a function lengthNum so that it will only return the length of a list of numbers. (i.e. it will not work for any other type of list, e.g. a list of String).
时间: 2024-01-08 16:02:37 浏览: 84
java.sql.SQLException: 内部错误: Unable to construct a Datum from the specified input
5星 · 资源好评率100%
Here's an implementation of `lengthNum` function in Haskell that only works for lists of numbers:
```haskell
lengthNum :: Num a => [a] -> Int
lengthNum xs = length xs
```
The function takes a list of type `[a]`, where `a` is any numeric type, and returns its length as an `Int`. Since the input type is constrained to only numeric types, it will not work for any other type of list, such as a list of `String`. The `Num` typeclass constraint ensures that only numeric types are allowed as inputs.
阅读全文