在ghci中输入默认值 [英] Type defaulting in ghci

查看:81
本文介绍了在ghci中输入默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GHCi作为我的解释器,

我的任务规范是有一个元组列表 Int

  [(Int,Int)] 

当我输入

  let edges = [(0,2 ),(0,3),(1,2),(2,3)] 

GHCi自动使数字类型整数而不是 Int ,所以我无法测试我的程序,即

 :t edges 
edges :: [(Integer,Integer)]

如何强制使用 Int 而不是整数 ??



谢谢!

解决方案

您可以指定类型,如下所示:

  let edges = [(0,2),(0, 3),(1,2),(2,3)] :: [(Int,Int)] 


I am using GHCi as my interpreter,

The specifications for my assignment are to have a list of tuples of Ints ie

[(Int,Int)]

when I type

let edges = [(0,2),(0,3),(1,2),(2,3)]

GHCi automatically makes the number types Integer instead of Int, so I can't test my program ie,

:t edges
edges :: [(Integer,Integer)]

How can I force a definition like that to use Int, instead of Integer??

Thanks!

解决方案

You can specify the type when you enter it like this:

let edges = [(0,2),(0,3),(1,2),(2,3)] :: [(Int, Int)]

这篇关于在ghci中输入默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆