CodeWorld Intro

Code World provides an animation framework that is a lot like Racket’s big-bang.

  • Use code.world/haskell. This is the full-featured environment. If you go to “plain” CodeWorld without the haskell, you will be using a limited and modified version of Haskell… you want the real thing.

  • Header: you should start every program with the few lines below.

      {-# LANGUAGE OverloadedStrings #-}
      import CodeWorld
      import qualified Data.Text as T
      main = drawingOf coordinatePlane
    
  • The CodeWorld Reference Desk specific to Haskell is pretty minimal. The Beginner’s Help Desk is quite a bit easier to read. Unfortunately, the functions have been “beginner-ized” (see below).

Beginner Guide

The Part 1: Expressions section of the Beginner’s Guide is great. It introduces all of the main graphics functions and how to use them. Unfortunately, how they work has been “simplified” so you will probably need to read the full Haskell guide to see how to use them.

As an example of “beginner-ization”, the following code is the correct Haskell way to make a circle of radius 5 and move its center to (3,4).

  c = circle 5.0
  d = translated 3.0 4.0 c

In the beginner version, the second line has to be written a different way.

   d = translated(c, 3.0, 4.0)  -- not in Haskell, do not use

You will need to “undo” this kind of transformation to use the code examples.

A similar problem happens with colored.

OverloadedStrings Explained

Haskell has more than one type of string. It turns out that the basic “list of Char” that we use is not good for some applications, so real Haskell programs generally use a more complex type of string. The OverloadedStrings option tells Haskell that it is ok to interpret "quoted words" in your code as one of the fancy types of string. You can read a blog post about the complexity of Haskell’s strings if you want.

The most common functions to need are T.pack to make a normal String into a fancy string, and T.append to append to fancy strings.

You should only need to read the Data.Text documentation if you are doing something unusual with user input.

Last modified October 2, 2023: Typo. (561e142)