How to merge two hands of cards together in Haskell?

泄露秘密 提交于 2019-12-11 14:43:00

问题


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.


回答1:


The definition should either be

h1 <+ h2 = undefined

or

(<+) h1 h2 = undefined

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



来源:https://stackoverflow.com/questions/58938019/how-to-merge-two-hands-of-cards-together-in-haskell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!