Skip to content

Instantly share code, notes, and snippets.

@SHoltzen
Last active March 9, 2024 21:57
Show Gist options
  • Save SHoltzen/601e5a763c42114c5e6356adfc0b44db to your computer and use it in GitHub Desktop.
Save SHoltzen/601e5a763c42114c5e6356adfc0b44db to your computer and use it in GitHub Desktop.
Quiz #1 makeup starter code
#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