Last active
March 9, 2024 21:57
-
-
Save SHoltzen/601e5a763c42114c5e6356adfc0b44db to your computer and use it in GitHub Desktop.
Quiz #1 makeup starter code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang plait | |
(define-type Pokemon | |
(pre-evo (name : String) (evo : Pokemon)) | |
(final-evo (name : String))) | |
(define-type-alias Pokedex (Listof Pokemon)) | |
(define (get-name p) | |
(type-case Pokemon p | |
[(pre-evo n evo) n] | |
[(final-evo n) n])) | |
; buggy implementation: fix this | |
(get-pre-evo : (String (Listof Pokemon) -> Pokemon)) | |
(define (get-pre-evo pkmn dex) | |
(type-case Pokedex dex | |
[empty (error 'NoPkmn "Not found")] | |
[(cons p l) (if (equal? (get-name (pre-evo-evo p)) pkmn) p (get-pre-evo pkmn l))])) | |
; provide tests here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment