Pie语言:手册代码在DrRacket中运行出错的问题咨询
Hey there! Let's break down your two issues with Pie—the dependently typed language from The Little Typer—step by step:
1. Why does (cons 'ratatouille 'baguette) throw "Can't determine a type"?
Pie is a strict dependently typed language—unlike standard Scheme, it doesn’t automatically infer the type of your cons call without explicit hints. Here’s what’s going on:
- In Pie,
consisn’t a built-in polymorphic function that works for any type out of the box. It’s tightly tied to thePairtype, which requires you to specify the exact types of the car and cdr upfront. - To fix this, you need to explicitly declare the type of your pair before defining it. For example:
This tells Pie exactly what type we’re constructing, so the type checker can validate the; First, declare the type of your pair (claim my-french-snack (Pair Atom Atom)) ; Then define the pair with cons (define my-french-snack (cons 'ratatouille 'baguette))conscall correctly.
2. Does Pie have a prelude for basic functions like +?
Absolutely! Pie comes with a standard prelude that defines core functions (like +, *), types (like Nat, Pair, List), and utility helpers—this is what The Little Typer assumes you’re using. Here’s how to set it up in DrRacket:
- First, install the Pie package: Go to File > Package Manager, search for
pie, and install it. - At the top of your Pie file, use the Pie language and load the prelude:
Once loaded, you’ll have access to#lang pie (load "pie/prelude.pie") ; Path may vary slightly based on your installation+(for natural numbers), properly typedcons, and all the other core functionality covered in the book.
A quick tip: Always follow the book’s code structure closely—Pie’s syntax and type system are very intentional, so skipping type declarations or forgetting to load the prelude will lead to these kinds of errors.
内容的提问来源于stack exchange,提问作者Dess

