Skip to content

Instantly share code, notes, and snippets.

@YuraKostin
Last active October 23, 2020 11:16
Show Gist options
  • Save YuraKostin/c0bae81aca317c70d241a0067614d335 to your computer and use it in GitHub Desktop.
Save YuraKostin/c0bae81aca317c70d241a0067614d335 to your computer and use it in GitHub Desktop.
Will Kurt. Lesson 10
robots.hs:47:36: error:
• Couldn't match type ‘[Char]’
with ‘((a1, b1, [Char]) -> t1) -> t1’
Expected type: ((a1, b1, [Char]) -> ((a1, b1, [Char]) -> t1) -> t1)
-> ((((a1, b1, [Char]) -> t1) -> t1, b1,
((a1, b1, [Char]) -> t1) -> t1)
-> ((a1, b1, [Char]) -> t1) -> t1)
-> [Char]
Actual type: ((((a1, b1, [Char]) -> t1) -> t1, b1,
((a1, b1, [Char]) -> t1) -> t1)
-> ((a1, b1, [Char]) -> t1) -> t1)
-> [Char]
• In the second argument of ‘fight’, namely ‘robotB’
In the expression: fight robotA robotB
In an equation for ‘bAfterRound’: bAfterRound = fight robotA robotB
• Relevant bindings include
bAfterRound :: ((((a1, b1, [Char]) -> t1) -> t1, b1,
((a1, b1, [Char]) -> t1) -> t1)
-> ((a1, b1, [Char]) -> t1) -> t1)
-> [Char]
(bound at robots.hs:47:9)
robotB :: ((((a1, b1, [Char]) -> t1) -> t1, b1,
((a1, b1, [Char]) -> t1) -> t1)
-> ((a1, b1, [Char]) -> t1) -> t1)
-> [Char]
(bound at robots.hs:46:20)
fightRounds :: (((((a, b, [Char]) -> t) -> t,
((a, b, [Char]) -> t) -> t, ((a, b, [Char]) -> t) -> t)
-> ((a, b, [Char]) -> t) -> t)
-> [Char])
-> (((((a1, b1, [Char]) -> t1) -> t1, b1,
((a1, b1, [Char]) -> t1) -> t1)
-> ((a1, b1, [Char]) -> t1) -> t1)
-> [Char])
-> t2
-> [Char]
(bound at robots.hs:36:1)
|
47 | where bAfterRound = fight robotA robotB
| ^^^^^^
robots.hs:48:41: error:
• Couldn't match type ‘[Char]’
with ‘((((a, b, [Char]) -> t) -> t, ((a, b, [Char]) -> t) -> t,
((a, b, [Char]) -> t) -> t)
-> ((a, b, [Char]) -> t) -> t)
-> [Char]’
Expected type: ((a, b, [Char]) -> ((a, b, [Char]) -> t) -> t)
-> ((((a, b, [Char]) -> t) -> t, ((a, b, [Char]) -> t) -> t,
((a, b, [Char]) -> t) -> t)
-> ((a, b, [Char]) -> t) -> t)
-> [Char]
Actual type: ((((a, b, [Char]) -> t) -> t,
((a, b, [Char]) -> t) -> t, ((a, b, [Char]) -> t) -> t)
-> ((a, b, [Char]) -> t) -> t)
-> [Char]
• In the second argument of ‘fight’, namely ‘robotA’
In the expression: fight bAfterRound robotA
In an equation for ‘aAfterRound’:
aAfterRound = fight bAfterRound robotA
• Relevant bindings include
aAfterRound :: ((((a, b, [Char]) -> t) -> t,
((a, b, [Char]) -> t) -> t, ((a, b, [Char]) -> t) -> t)
-> ((a, b, [Char]) -> t) -> t)
-> [Char]
(bound at robots.hs:48:9)
robotA :: ((((a, b, [Char]) -> t) -> t, ((a, b, [Char]) -> t) -> t,
((a, b, [Char]) -> t) -> t)
-> ((a, b, [Char]) -> t) -> t)
-> [Char]
(bound at robots.hs:46:13)
fightRounds :: (((((a, b, [Char]) -> t) -> t,
((a, b, [Char]) -> t) -> t, ((a, b, [Char]) -> t) -> t)
-> ((a, b, [Char]) -> t) -> t)
-> [Char])
-> (((((a1, b1, [Char]) -> t1) -> t1, b1,
((a1, b1, [Char]) -> t1) -> t1)
-> ((a1, b1, [Char]) -> t1) -> t1)
-> [Char])
-> t2
-> [Char]
(bound at robots.hs:36:1)
|
48 | aAfterRound = fight bAfterRound robotA
| ^^^^^^
robot (name, attack, hp) = \message -> message (name, attack, hp)
name (n, _, _) = n
attack (_, a, _) = a
hp (_, _, hp) = hp
getName aRobot = aRobot name
getAttack aRobot = aRobot attack
getHP aRobot = aRobot hp
setName aRobot newName = aRobot (\(_, a, h) -> robot (newName, a, h))
setAttack aRobot newAttack = aRobot (\(n, _, h) -> robot (n, newAttack, h))
setHP aRobot newHP = aRobot (\(n, a, _) -> robot (n, a, newHP))
printRobot aRobot = aRobot (\(n, a, h) -> n ++ " attack: " ++ (show a) ++ " hp: " ++ show(h))
damage aRobot attackDamage = aRobot (\(n, a, h) -> robot (n, a, h - attackDamage))
fight attacker defender = damage defender attack
where attack = if attackerHP > 10
then getAttack attacker
else 0
attackerHP = getHP attacker
fightRounds robotA robotB 0 = if aHP > bHP
then aName ++ " won the fight!"
else if aHP < bHP
then bName ++ " won the fight!"
else "There is no winner!"
where aHP = getHP robotA
aName = getName robotA
bHP = getHP robotB
bName = getName robotB
fightRounds robotA robotB fights = fightRounds aAfterRound bAfterRound (fights - 1)
where bAfterRound = fight robotA robotB
aAfterRound = fight bAfterRound robotA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment