如何在Haskell中将两只手牌合并在一起? [英] How to merge two hands of cards together in Haskell?

查看:132
本文介绍了如何在Haskell中将两只手牌合并在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Haskell还是很陌生,我很好奇如何将两个Hand合并在一起,因此,第一只手放在第二只手的顶部.我希望它成为中缀运算符,即(< +).这里有一些代码可以为您提供帮助.我不断收到错误消息,说< +"的类型签名缺少附带的绑定".

I'm still very new to Haskell, and I'm curious as to how I would merge two Hand's together, so that, the first hand is placed on top of the second hand. I want it to be an infix operator, namely (<+). Here's some code to assist you. I keep getting an error saying "The type signature for ‘<+’ lacks an accompanying binding".

data Rank = Numeric Integer | Jack | Queen | King | Ace

data Suit = Hearts | Spades | Diamonds | Clubs

data Card = Card Rank Suit

data Hand = Empty | Add Card Hand

(<+) :: Hand -> Hand -> Hand
h1 (<+) h2 = undefined

在此先感谢您提供任何建议.

Many thanks in advance for any advice given.

推荐答案

定义应为

h1 <+ h2 = undefined

(<+) h1 h2 = undefined

您当前正在尝试使用函数名称作为中缀运算符.

You are currently trying to use a function name as an infix operator.

这篇关于如何在Haskell中将两只手牌合并在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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