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

Rumen Hristov

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 work around this issue?

This is what I am trying to achieve: (it does not 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 so.

Sebastian Redl

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

检查int或list <int>

来自分类Dev

Haskell作业-小数列表[Int]-> Int

来自分类Dev

How to return item index from list SML?

来自分类Dev

Haskell的部门,Type类

来自分类Dev

如何排序List <Integer>?

来自分类Dev

How to json.loads as list instead of dictionary in Python

来自分类Dev

How to destroy elements (or shorten length) of list array in C#

来自分类Dev

Filter list items by length in Haskell

来自分类Dev

在Haskell中将Int划分为Int

来自分类Dev

tree with defined Type in haskell

来自分类Dev

Haskell中的Int文字

来自分类Dev

Swift中的Int vs Integer

来自分类Dev

Why does Scala's indexOf (in List etc) return Int instead of Option[Int]?

来自分类Dev

how to return the last type of a variadic template?

来自分类Dev

如何在Haskell中以Integer类型而不是Int类型返回列表的长度

来自分类Dev

How do I build a list with a dependently-typed length?

来自分类Dev

Haskell - replicate elements in a list

来自分类Dev

查找Haskell Int精度

来自分类Dev

Haskell:具有int签名的Integer到Int

来自分类Dev

不同的List <List <int >>?

来自分类Dev

How to detect if a type is one of a list of generic types

来自分类Dev

Haskell:将Integer除以Integer并获得Double

来自分类Dev

Haskell-理解:t [length,head]定义

来自分类Dev

基本haskell:将[[int]]转换为[int]

来自分类Dev

对每个集合使用Integer或int

来自分类Dev

Haskell中的Int文字

来自分类Dev

查找Haskell Int精度

来自分类Dev

Haskell concat Int

来自分类Dev

Haskell除以Int的倍数