Newbie pattern matching

Ashe 2018-03-13 06:05:50.263937 UTC

1-- Takes a list of animationsets and returns the correct set
2getAnimationSet :: [AnimationSet] -> String -> String -> Maybe AnimationSet
3getAnimationSet sets entity tag = case filter checkSets sets of
4 [] -> Nothing
5 [x : _] -> Just x
6 where checkSets (AnimationSet entity' tag' _) = entity == entity' && tag == tag'
7
8
9
10-- Takes an animation set and returns an animation
11getAnimation :: AnimationSet -> String -> Maybe Animation
12getAnimation (AnimationSet _ _ anims) animName = case filter checkAnim anims of
13 [] -> Nothing
14 [x : xs] -> Just x
15 where checkAnim (Animation name _ _) = name == animName
16
17
18{-
19/home/ashe/Documents/FirstGameHS/src/SDLAnimations.hs:50:34: error:
20 • Couldn't match expected type ‘AnimationSet’
21 with actual type ‘[AnimationSet]’
22 • In the pattern: x : _
23 In the pattern: [x : _]
24 In a case alternative: [x : _] -> Just x
25 |
2650 | [x : _] -> Just x
27 | ^^^^^
28
29/home/ashe/Documents/FirstGameHS/src/SDLAnimations.hs:57:56: error:
30 • Couldn't match expected type ‘Animation’
31 with actual type ‘[Animation]’
32 • In the pattern: x : xs
33 In the pattern: [x : xs]
34 In a case alternative: [x : xs] -> Just x
35 |
3657 | [x : xs] -> Just x
37 | ^^^^^^
38
39}-