How to return list length as Integer instead of Int in Haskell

I am trying to return the length of a list as an Integer type, but applying length xs returns the length as an Int type. How can I get around this problem?

This is what I'm trying to achieve: (it doesn't work)

 sizeList :: [Integer] -> Integer sizeList xs = length xs 

It works as soon as I change the return to sizeList :: [Integer] -> Int , but I don't want to do this.

+5
source share
1 answer

You can call genericLength from a Data.List or call length and use fromIntegral to convert the result.

+13
source

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


All Articles