codeworld-base-0.2.0.0: Replacement base module for CodeWorld

Safe HaskellNone
LanguageHaskell98

Prelude

Contents

Description

The standard set of functions and variables available to all programs.

You may use any of these functions and variables without defining them.

Synopsis

Documentation

Welome to CodeWorld! You can define your own pictures, animations, and games by defining variables and functions. There are four kinds of CodeWorld programs:

  • Pictures. To create a picture, you'll define the variable called main using pictureOf. The parameter to pictureOf should be a Picture. Example:
main = pictureOf(tree)
  • Animations. To create an animation, you'll define the variable called main using animationOf. The parameter to animationOf should be a function, mapping each time in seconds (a Number) to a Picture that is shown at that time. Example:
main = animationOf(spinningWheel)
  • Simulations. A simulation is like an animation, in that it changes over time. But while an animation changes in a simple regular way over time, a simulation can change in different ways depending on the state of things at any moment. To create a simulation, you should first decide on the type to describe the state of things (called the "world" type), and describe the simulation in terms of the starting state, the step that says how things change over time, and and a draw function that can build a picture from a state. Then you'll use simulationOf to define main. Example:
main = simulationOf(start, step, draw)
  • Interactions. Finally, you can build an interactive simulation, such as a game. This is very like a simulation, except that it also has an event function, which says how the state of things changes when events (like keys being pressed or the mouse moving) happen. You'll use interactionOf to define these. Example:
main = interactionOf(start, step, event, draw)

Numbers

data Number #

The type for numbers.

Numbers can be positive or negative, whole or fractional. For example, 5, 3.2, and -10 are all values of the type Number.

Instances

Enum Number # 
Eq Number # 

Methods

(==) :: Number -> Number -> Bool

(/=) :: Number -> Number -> Bool

Floating Number # 
Fractional Number # 

Methods

(/) :: Number -> Number -> Number

recip :: Number -> Number

fromRational :: Rational -> Number

Num Number # 
Ord Number # 

Methods

compare :: Number -> Number -> Ordering

(<) :: Number -> Number -> Bool

(<=) :: Number -> Number -> Bool

(>) :: Number -> Number -> Bool

(>=) :: Number -> Number -> Bool

max :: Number -> Number -> Number

min :: Number -> Number -> Number

Real Number # 

Methods

toRational :: Number -> Rational

RealFloat Number # 

Methods

floatRadix :: Number -> Integer

floatDigits :: Number -> Int

floatRange :: Number -> (Int, Int)

decodeFloat :: Number -> (Integer, Int)

encodeFloat :: Integer -> Int -> Number

exponent :: Number -> Int

significand :: Number -> Number

scaleFloat :: Int -> Number -> Number

isNaN :: Number -> Bool

isInfinite :: Number -> Bool

isDenormalized :: Number -> Bool

isNegativeZero :: Number -> Bool

isIEEE :: Number -> Bool

atan2 :: Number -> Number -> Number

RealFrac Number # 

Methods

properFraction :: Integral b => Number -> (b, Number)

truncate :: Integral b => Number -> b

round :: Integral b => Number -> b

ceiling :: Integral b => Number -> b

floor :: Integral b => Number -> b

Show Number # 

Methods

showsPrec :: Int -> Number -> ShowS

show :: Number -> String

showList :: [Number] -> ShowS

(+) :: Number -> Number -> Number infixl 6 #

Adds two numbers.

(-) :: Number -> Number -> Number infixl 6 #

Subtracts two numbers.

(*) :: Number -> Number -> Number infixl 7 #

Multiplies two numbers.

(/) :: HasCallStack => Number -> Number -> Number infixl 7 #

Divides two numbers. The second number should not be zero.

(^) :: HasCallStack => Number -> Number -> Number infixr 8 #

Raises a number to a power.

(>) :: Number -> Number -> Truth infix 4 #

Tells whether one number is greater than the other.

(>=) :: Number -> Number -> Truth infix 4 #

Tells whether one number is greater than or equal to the other.

(<) :: Number -> Number -> Truth infix 4 #

Tells whether one number is less than the other.

(<=) :: Number -> Number -> Truth infix 4 #

Tells whether one number is less than or equal to the other.

max :: (Number, Number) -> Number #

Gives the larger of two numbers.

min :: (Number, Number) -> Number #

Gives the smaller of two numbers.

opposite :: Number -> Number #

Gives the opposite (that is, the negative) of a number.

abs :: Number -> Number #

Gives the absolute value of a number.

If the number if positive or zero, the absolute value is the same as the number. If the number is negative, the absolute value is the opposite of the number.

signum :: Number -> Number #

Gives the sign of a number.

If the number is negative, the signum is -1. If it's positive, the signum is 1. If the number is 0, the signum is 0. In general, a number is equal to its absolute value (abs) times its sign (signum).

truncation :: Number -> Number #

Gives the number without its fractional part.

For example, truncate(4.2) is 4, while truncate(-4.7) is -4.

rounded :: Number -> Number #

Gives the number rounded to the nearest integer.

For example, round(4.2) is 4, while round(4.7) is 5.

ceiling :: Number -> Number #

Gives the smallest integer that is greater than or equal to a number.

For example, ceiling(4) is 4, while ceiling(4.1) is 5. With negative numbers, ceiling(-3.5) is -3, since -3 is greater than -3.5.

floor :: Number -> Number #

Gives the largest integer that is less than or equal to a number.

For example, floor(4) is 4, while floor(3.9) is 3. With negative numbers, floor(-3.5) is -4, since -4 is less than -3.5.

quotient :: HasCallStack => (Number, Number) -> Number #

Gives the integer part of the result when dividing two numbers.

For example, 3/2 is 1.5, but quotient(3, 2) is 1, which is the integer part.

remainder :: HasCallStack => (Number, Number) -> Number #

Gives the remainder when dividing two numbers.

For example, remainder(3,2) is 1, which is the remainder when dividing 3 by 2.

reciprocal :: HasCallStack => Number -> Number #

Gives the repicrocal of a number.

For example, reciprocal(5) is 1/5 (also written as 0.2).

pi :: Number #

The constant pi, which is equal to the ration between the circumference and diameter of a circle.

pi is approximately 3.14159.

exp :: Number -> Number #

Gives the exponential of a number. This is equal to the constant e, raised to the power of the number.

The exp function increases faster and faster very quickly. For example, if t is the current time in seconds, exp(t) will reach a million in about 14 seconds. It will reach a billion in around 21 seconds.

sqrt :: HasCallStack => Number -> Number #

Gives the square root of a number. This is the positive number that, when multiplied by itself, gives the original number back.

The sqrt always increases, but slows down. For example, if t is the current time, sqrt(t) will reach 5 in 25 seconds. But it will take 100 seconds to reach 10, and 225 seconds (almost 4 minutes) to reach 15.

squareRoot :: HasCallStack => Number -> Number #

log :: HasCallStack => Number -> Number #

Gives the natural log of a number. This is the opposite of the exp function.

Like sqrt, the log function always increases, but slows down. However, it slows down much sooner than the sqrt function. If t is the current time in seconds, it takes more than 2 minutes for log(t) to reach 5, and more than 6 hours to reach 10!

logBase :: HasCallStack => (Number, Number) -> Number #

Gives the logarithm of the first number, using the base of the second number.

sin :: Number -> Number #

Gives the sine of an angle, where the angle is measured in degrees.

tan :: Number -> Number #

Gives the tangent of an angle, where the angle is measured in degrees.

This is the slope of a line at that angle from horizontal.

cos :: Number -> Number #

Gives the cosine of an angle, where the angle is measured in degrees.

asin :: HasCallStack => Number -> Number #

Gives the inverse sine of a value, in degrees.

This is the unique angle between -90 and 90 that has the input as its sine.

atan :: Number -> Number #

Gives the inverse tangent of a value, in degrees.

This is the unique angle between -90 and 90 that has the input as its tangent.

atan2 :: (Number, Number) -> Number #

Warning: Please use vectorDirection instead of atan2.

Gives the angle between the positive x axis and a given point, in degrees.

acos :: HasCallStack => Number -> Number #

Gives the inverse cosine of a value, in degrees.

This is the unique angle between 0 and 180 that has the input as its cosine.

properFraction :: Number -> (Number, Number) #

Separates a number into its whole and fractional parts.

For example, properFraction(1.2) is (1, 0.2).

even :: Number -> Truth #

Tells if a number is even.

odd :: Number -> Truth #

Tells if a number is odd.

gcd :: HasCallStack => (Number, Number) -> Number #

Gives the greatest common divisor of two numbers.

This is the largest number that divides each of the two parameters. Both parameters must be integers.

lcm :: HasCallStack => (Number, Number) -> Number #

Gives the least common multiple of two numbers.

This is the smallest number that is divisible by both of the two parameters. Both parameters must be integers.

sum :: [Number] -> Number #

Gives the sum of a list of numbers.

product :: [Number] -> Number #

Gives the product of a list of numbers.

maximum :: [Number] -> Number #

Gives the largest number from a list.

minimum :: [Number] -> Number #

Gives the smallest number from a list.

isInteger :: Number -> Truth #

Tells whether a Number is an integer or not.

An integer is a whole number, such as 5, 0, or -10. Numbers with non-zero decimals, like 5.3, are not integers.

fromInteger :: Integer -> Number #

fromRational :: Rational -> Number #

fromInt :: Int -> Number #

toInt :: HasCallStack => Number -> Int #

fromDouble :: HasCallStack => Double -> Number #

toDouble :: Number -> Double #

Text

data Text #

Instances

Eq Text # 

Methods

(==) :: Text -> Text -> Bool

(/=) :: Text -> Text -> Bool

fromString :: String -> Text #

toString :: Text -> String #

fromCWText :: Text -> Text #

toCWText :: Text -> Text #

(<>) :: Text -> Text -> Text infixr 6 #

lines :: Text -> [Text] #

unlines :: [Text] -> Text #

words :: Text -> [Text] #

unwords :: [Text] -> Text #

joined :: [Text] -> Text #

substitution :: (Text, Text, Text) -> Text #

Gives the result of replacing one piece of text with another.

For example, `substitution("How do you do?", "do", "be")` is equal to `"How be you be?"`.

substitutions :: (Text, [(Text, Text)]) -> Text #

Gives the result of performing many substitutions in a piece of text. This is commonly used to build text to show in a program, as in this example:

substitutions("Lives: [lives] of 3 Score: [score]", [("[lives]", printed(lives)), ("[score]", printed(score))])

General purpose functions

ifThenElse :: Truth -> a -> a -> a #

fail :: HasCallStack => String -> a #

Fails with an error message. This is required (though apparently unused) by the desugaring for pattern binds in list comprehensions.

(==) :: a -> a -> Truth infix 4 #

Compares values to see if they are equal.

(/=) :: a -> a -> Truth infix 4 #

Compares values to see if they are not equal. Note that `a /= b` is the same as `not (a == b)`.

type Truth = Bool #

data Bool :: * #

Constructors

False 
True 

Instances

Bounded Bool 
Enum Bool 

Methods

succ :: Bool -> Bool

pred :: Bool -> Bool

toEnum :: Int -> Bool

fromEnum :: Bool -> Int

enumFrom :: Bool -> [Bool]

enumFromThen :: Bool -> Bool -> [Bool]

enumFromTo :: Bool -> Bool -> [Bool]

enumFromThenTo :: Bool -> Bool -> Bool -> [Bool]

Eq Bool 

Methods

(==) :: Bool -> Bool -> Bool

(/=) :: Bool -> Bool -> Bool

Ord Bool 

Methods

compare :: Bool -> Bool -> Ordering

(<) :: Bool -> Bool -> Bool

(<=) :: Bool -> Bool -> Bool

(>) :: Bool -> Bool -> Bool

(>=) :: Bool -> Bool -> Bool

max :: Bool -> Bool -> Bool

min :: Bool -> Bool -> Bool

Show Bool 

Methods

showsPrec :: Int -> Bool -> ShowS

show :: Bool -> String

showList :: [Bool] -> ShowS

Ix Bool 

Methods

range :: (Bool, Bool) -> [Bool]

index :: (Bool, Bool) -> Bool -> Int

unsafeIndex :: (Bool, Bool) -> Bool -> Int

inRange :: (Bool, Bool) -> Bool -> Bool

rangeSize :: (Bool, Bool) -> Int

unsafeRangeSize :: (Bool, Bool) -> Int

Generic Bool 

Associated Types

type Rep Bool :: * -> *

Methods

from :: Bool -> Rep Bool x

to :: Rep Bool x -> Bool

Bits Bool 

Methods

(.&.) :: Bool -> Bool -> Bool

(.|.) :: Bool -> Bool -> Bool

xor :: Bool -> Bool -> Bool

complement :: Bool -> Bool

shift :: Bool -> Int -> Bool

rotate :: Bool -> Int -> Bool

zeroBits :: Bool

bit :: Int -> Bool

setBit :: Bool -> Int -> Bool

clearBit :: Bool -> Int -> Bool

complementBit :: Bool -> Int -> Bool

testBit :: Bool -> Int -> Bool

bitSizeMaybe :: Bool -> Maybe Int

bitSize :: Bool -> Int

isSigned :: Bool -> Bool

shiftL :: Bool -> Int -> Bool

unsafeShiftL :: Bool -> Int -> Bool

shiftR :: Bool -> Int -> Bool

unsafeShiftR :: Bool -> Int -> Bool

rotateL :: Bool -> Int -> Bool

rotateR :: Bool -> Int -> Bool

popCount :: Bool -> Int

FiniteBits Bool 

Methods

finiteBitSize :: Bool -> Int

countLeadingZeros :: Bool -> Int

countTrailingZeros :: Bool -> Int

Random Bool 

Methods

randomR :: RandomGen g => (Bool, Bool) -> g -> (Bool, g)

random :: RandomGen g => g -> (Bool, g)

randomRs :: RandomGen g => (Bool, Bool) -> g -> [Bool]

randoms :: RandomGen g => g -> [Bool]

randomRIO :: (Bool, Bool) -> IO Bool

randomIO :: IO Bool

Unbox Bool 
SingI Bool False 

Methods

sing :: Sing False a

SingI Bool True 

Methods

sing :: Sing True a

Vector Vector Bool 

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) Bool -> m (Vector Bool)

basicUnsafeThaw :: PrimMonad m => Vector Bool -> m (Mutable Vector (PrimState m) Bool)

basicLength :: Vector Bool -> Int

basicUnsafeSlice :: Int -> Int -> Vector Bool -> Vector Bool

basicUnsafeIndexM :: Monad m => Vector Bool -> Int -> m Bool

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) Bool -> Vector Bool -> m ()

elemseq :: Vector Bool -> Bool -> b -> b

MVector MVector Bool 

Methods

basicLength :: MVector s Bool -> Int

basicUnsafeSlice :: Int -> Int -> MVector s Bool -> MVector s Bool

basicOverlaps :: MVector s Bool -> MVector s Bool -> Bool

basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) Bool)

basicInitialize :: PrimMonad m => MVector (PrimState m) Bool -> m ()

basicUnsafeReplicate :: PrimMonad m => Int -> Bool -> m (MVector (PrimState m) Bool)

basicUnsafeRead :: PrimMonad m => MVector (PrimState m) Bool -> Int -> m Bool

basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) Bool -> Int -> Bool -> m ()

basicClear :: PrimMonad m => MVector (PrimState m) Bool -> m ()

basicSet :: PrimMonad m => MVector (PrimState m) Bool -> Bool -> m ()

basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) Bool -> MVector (PrimState m) Bool -> m ()

basicUnsafeMove :: PrimMonad m => MVector (PrimState m) Bool -> MVector (PrimState m) Bool -> m ()

basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) Bool -> Int -> m (MVector (PrimState m) Bool)

SingKind Bool (KProxy Bool) 

Associated Types

type DemoteRep (KProxy Bool) (kparam :: KProxy (KProxy Bool)) :: *

Methods

fromSing :: Sing (KProxy Bool) a -> DemoteRep (KProxy Bool) kparam

type Rep Bool 
type Rep Bool = D1 (MetaData "Bool" "GHC.Types" "ghc-prim" False) ((:+:) (C1 (MetaCons "False" PrefixI False) U1) (C1 (MetaCons "True" PrefixI False) U1))
data Sing Bool 
data Sing Bool where
data Vector Bool 
data Vector Bool = V_Bool (Vector Word8)
data MVector s Bool 
data MVector s Bool = MV_Bool (MVector s Word8)
type (==) Bool a b 
type (==) Bool a b = EqBool a b
type DemoteRep Bool (KProxy Bool) 
type DemoteRep Bool (KProxy Bool) = Bool

(&&) :: Truth -> Truth -> Truth infixr 3 #

(||) :: Truth -> Truth -> Truth infixr 2 #

toOperator :: ((a, b) -> c) -> a -> b -> c #

Converts a function to an operator.

Example use:

f(x,y) = 2*x + y (%) = toOperator(f)

eight = 3 % 2

This has the same effect as defining % as:

x % y = 2*x + y eight = 3 % 2

fromOperator :: (a -> b -> c) -> (a, b) -> c #

Converts an operator into a normal function.

Example use:

divide = fromOperator(/) four = divide(16, 4)

id :: a -> a #

(.) :: (b -> c) -> (a -> b) -> a -> c #

firstOfPair :: (a, b) -> a #

Returns the first element of an ordered pair.

secondOfPair :: (a, b) -> b #

Returns the second element of an ordered pair.

error :: HasCallStack => Text -> a #

Fails with an error message.

undefined :: HasCallStack => a #

Represents an undefined value. This lets you compile programs with unfinished values. If the value is needed, the program will crash.

(++) :: [a] -> [a] -> [a] #

empty :: [a] -> Truth #

Determines whether a list is empty or not.

contains :: ([a], a) -> Truth #

Determines whether a value is a member of a list or not.

length :: [a] -> Number #

Gives the length of a list.

at :: HasCallStack => ([a], Number) -> a #

Gives the member of a list at a given index. Indices start at 0.

(#) :: HasCallStack => [a] -> Number -> a infixl 9 #

Gives the member of a list at a given index. Indices start at 0.

any :: [Truth] -> Truth #

Determines if any proposition in a list is true.

For example, `any([even(n) | n <- [1,2,3]])` is True, because 2 is even.

all :: [Truth] -> Truth #

Determines if all propositions in a list are true.

For example, `all([even(n) | n <- [2,3,4]])` is False, because 3 is not even.

none :: [Truth] -> Truth #

Determines if all propositions in a list are false.

For example, `none([odd(n) | n <- [2,3,4]])` is False, because 3 is odd.

repeated :: ([a], Number) -> [a] #

Forms a list by repeating a source list some number of times.

repeating :: [a] -> [a] #

Forms a list by repeating a source list forever.

first :: HasCallStack => ([a], Number) -> [a] #

Gives the first members of a list, up to the given number.

last :: HasCallStack => ([a], Number) -> [a] #

Gives the last members of a list, up to the given number.

rest :: HasCallStack => ([a], Number) -> [a] #

Gives all members of a list after the given number.

In general, `xs = first(xs, n) ++ rest(xs, n)`.

while :: ([a], a -> Truth) -> [a] #

Gives the longest prefix of a list for which a condition is true.

For example, `while([2,4,5,6], even) = [2,4]`.

until :: ([a], a -> Truth) -> [a] #

Gives the longest prefix of a list for which a condition is false.

For example, `until([2,4,5,6], odd) = [2,4]`.

after :: ([a], a -> Truth) -> [a] #

Gives the remaining portion of a list after the longest prefix for which a condition is true.

In general, `xs = while(xs, cond) ++ after(xs, cond)

concatenation :: [[a]] -> [a] #

Gives the concatenation of all of the lists in its input.

subsequences :: [a] -> [[a]] #

permutations :: [a] -> [[a]] #

sorted :: [Number] -> [Number] #

Gives a list of numbers reordered into increasing order.

reversed :: [a] -> [a] #

Gives a list in the opposite order of the original.

unique :: [a] -> [a] #

Gives a list with all duplicate members removed.

transposed :: [[a]] -> [[a]] #

combined :: HasCallStack => ((a, a) -> a, [a]) -> a #

Combines a list of values into a single value, by merging members with a function. The function should take two parameters, and should be associative (so `f(x,f(y,z)) = f(f(x,y),z)`). The list should be non-empty.

For example, `combined(fromOperator(+), [1, 3, 5])` is equal to `9`.

data Maybe a :: * -> * #

Constructors

Nothing 
Just a 

Instances

Monad Maybe 

Methods

(>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b

(>>) :: Maybe a -> Maybe b -> Maybe b

return :: a -> Maybe a

fail :: String -> Maybe a

Functor Maybe 

Methods

fmap :: (a -> b) -> Maybe a -> Maybe b

(<$) :: a -> Maybe b -> Maybe a

Applicative Maybe 

Methods

pure :: a -> Maybe a

(<*>) :: Maybe (a -> b) -> Maybe a -> Maybe b

(*>) :: Maybe a -> Maybe b -> Maybe b

(<*) :: Maybe a -> Maybe b -> Maybe a

Foldable Maybe 

Methods

fold :: Monoid m => Maybe m -> m

foldMap :: Monoid m => (a -> m) -> Maybe a -> m

foldr :: (a -> b -> b) -> b -> Maybe a -> b

foldr' :: (a -> b -> b) -> b -> Maybe a -> b

foldl :: (b -> a -> b) -> b -> Maybe a -> b

foldl' :: (b -> a -> b) -> b -> Maybe a -> b

foldr1 :: (a -> a -> a) -> Maybe a -> a

foldl1 :: (a -> a -> a) -> Maybe a -> a

toList :: Maybe a -> [a]

null :: Maybe a -> Bool

length :: Maybe a -> Int

elem :: Eq a => a -> Maybe a -> Bool

maximum :: Ord a => Maybe a -> a

minimum :: Ord a => Maybe a -> a

sum :: Num a => Maybe a -> a

product :: Num a => Maybe a -> a

Generic1 Maybe 

Associated Types

type Rep1 (Maybe :: * -> *) :: * -> *

Methods

from1 :: Maybe a -> Rep1 Maybe a

to1 :: Rep1 Maybe a -> Maybe a

Alternative Maybe 

Methods

empty :: Maybe a

(<|>) :: Maybe a -> Maybe a -> Maybe a

some :: Maybe a -> Maybe [a]

many :: Maybe a -> Maybe [a]

MonadPlus Maybe 

Methods

mzero :: Maybe a

mplus :: Maybe a -> Maybe a -> Maybe a

Show1 Maybe 

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Maybe a -> ShowS

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Maybe a] -> ShowS

Read1 Maybe 

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Maybe a)

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Maybe a]

Ord1 Maybe 

Methods

liftCompare :: (a -> b -> Ordering) -> Maybe a -> Maybe b -> Ordering

Eq1 Maybe 

Methods

liftEq :: (a -> b -> Bool) -> Maybe a -> Maybe b -> Bool

Eq a => Eq (Maybe a) 

Methods

(==) :: Maybe a -> Maybe a -> Bool

(/=) :: Maybe a -> Maybe a -> Bool

Ord a => Ord (Maybe a) 

Methods

compare :: Maybe a -> Maybe a -> Ordering

(<) :: Maybe a -> Maybe a -> Bool

(<=) :: Maybe a -> Maybe a -> Bool

(>) :: Maybe a -> Maybe a -> Bool

(>=) :: Maybe a -> Maybe a -> Bool

max :: Maybe a -> Maybe a -> Maybe a

min :: Maybe a -> Maybe a -> Maybe a

Show a => Show (Maybe a) 

Methods

showsPrec :: Int -> Maybe a -> ShowS

show :: Maybe a -> String

showList :: [Maybe a] -> ShowS

Generic (Maybe a) 

Associated Types

type Rep (Maybe a) :: * -> *

Methods

from :: Maybe a -> Rep (Maybe a) x

to :: Rep (Maybe a) x -> Maybe a

Semigroup a => Semigroup (Maybe a) 

Methods

(<>) :: Maybe a -> Maybe a -> Maybe a

sconcat :: NonEmpty (Maybe a) -> Maybe a

stimes :: Integral b => b -> Maybe a -> Maybe a

Monoid a => Monoid (Maybe a) 

Methods

mempty :: Maybe a

mappend :: Maybe a -> Maybe a -> Maybe a

mconcat :: [Maybe a] -> Maybe a

SingKind a (KProxy a) => SingKind (Maybe a) (KProxy (Maybe a)) 

Associated Types

type DemoteRep (KProxy (Maybe a)) (kparam :: KProxy (KProxy (Maybe a))) :: *

Methods

fromSing :: Sing (KProxy (Maybe a)) a -> DemoteRep (KProxy (Maybe a)) kparam

SingI (Maybe a) (Nothing a) 

Methods

sing :: Sing (Nothing a) a

SingI a a1 => SingI (Maybe a) (Just a a1) 

Methods

sing :: Sing (Just a a1) a

(Selector Meta s, ToJSON a) => RecordToPairs (S1 s (K1 i (Maybe a))) 

Methods

recordToPairs :: Options -> S1 s (K1 i (Maybe a)) a -> DList Pair

(Selector Meta s, ToJSON a) => RecordToEncoding (S1 s (K1 i (Maybe a))) 

Methods

recordToEncoding :: Options -> S1 s (K1 i (Maybe a)) a -> Builder

(Selector Meta s, FromJSON a) => FromRecord (S1 s (K1 i (Maybe a))) 

Methods

parseRecord :: Options -> Maybe Text -> Object -> Parser (S1 s (K1 i (Maybe a)) a)

type Rep1 Maybe 
type Rep1 Maybe = D1 (MetaData "Maybe" "GHC.Base" "base" False) ((:+:) (C1 (MetaCons "Nothing" PrefixI False) U1) (C1 (MetaCons "Just" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1)))
type Rep (Maybe a) 
type Rep (Maybe a) = D1 (MetaData "Maybe" "GHC.Base" "base" False) ((:+:) (C1 (MetaCons "Nothing" PrefixI False) U1) (C1 (MetaCons "Just" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))))
data Sing (Maybe a) 
data Sing (Maybe a) where
type (==) (Maybe k) a b 
type (==) (Maybe k) a b = EqMaybe k a b
type DemoteRep (Maybe a) (KProxy (Maybe a)) 
type DemoteRep (Maybe a) (KProxy (Maybe a)) = Maybe (DemoteRep a (KProxy a))

withDefault :: (Maybe a, a) -> a #

Converts a Maybe value to a plain value, by using a default.

For example, `withDefault(Nothing, 5)` is equal to 5, while `withDefault(Just(3), 5)` is equal to 3.

hasValue :: Maybe a -> Truth #

Determines if a Maybe has a value.

definitely :: HasCallStack => Maybe a -> a #

Extracts the value from a Maybe, and crashes the program if there is no such value.

randomsFrom :: StdGen -> [Number] #

shuffled :: ([a], Number) -> [a] #

data IO a :: * -> * #

Instances

Monad IO 

Methods

(>>=) :: IO a -> (a -> IO b) -> IO b

(>>) :: IO a -> IO b -> IO b

return :: a -> IO a

fail :: String -> IO a

Functor IO 

Methods

fmap :: (a -> b) -> IO a -> IO b

(<$) :: a -> IO b -> IO a

Applicative IO 

Methods

pure :: a -> IO a

(<*>) :: IO (a -> b) -> IO a -> IO b

(*>) :: IO a -> IO b -> IO b

(<*) :: IO a -> IO b -> IO a

Alternative IO 

Methods

empty :: IO a

(<|>) :: IO a -> IO a -> IO a

some :: IO a -> IO [a]

many :: IO a -> IO [a]

MonadPlus IO 

Methods

mzero :: IO a

mplus :: IO a -> IO a -> IO a

PrimMonad IO 

Associated Types

type PrimState (IO :: * -> *) :: *

Methods

primitive :: (State# (PrimState IO) -> (#VoidRep, PtrRepLifted, State# (PrimState IO), a#)) -> IO a

PrimBase IO 

Methods

internal :: IO a -> State# (PrimState IO) -> (#VoidRep, PtrRepLifted, State# (PrimState IO), a#)

Monoid a => Monoid (IO a) 

Methods

mempty :: IO a

mappend :: IO a -> IO a -> IO a

mconcat :: [IO a] -> IO a

type PrimState IO 
type PrimState IO = RealWorld

data Number #

The type for numbers.

Numbers can be positive or negative, whole or fractional. For example, 5, 3.2, and -10 are all values of the type Number.

Instances

Enum Number # 
Eq Number # 

Methods

(==) :: Number -> Number -> Bool

(/=) :: Number -> Number -> Bool

Floating Number # 
Fractional Number # 

Methods

(/) :: Number -> Number -> Number

recip :: Number -> Number

fromRational :: Rational -> Number

Num Number # 
Ord Number # 

Methods

compare :: Number -> Number -> Ordering

(<) :: Number -> Number -> Bool

(<=) :: Number -> Number -> Bool

(>) :: Number -> Number -> Bool

(>=) :: Number -> Number -> Bool

max :: Number -> Number -> Number

min :: Number -> Number -> Number

Real Number # 

Methods

toRational :: Number -> Rational

RealFloat Number # 

Methods

floatRadix :: Number -> Integer

floatDigits :: Number -> Int

floatRange :: Number -> (Int, Int)

decodeFloat :: Number -> (Integer, Int)

encodeFloat :: Integer -> Int -> Number

exponent :: Number -> Int

significand :: Number -> Number

scaleFloat :: Int -> Number -> Number

isNaN :: Number -> Bool

isInfinite :: Number -> Bool

isDenormalized :: Number -> Bool

isNegativeZero :: Number -> Bool

isIEEE :: Number -> Bool

atan2 :: Number -> Number -> Number

RealFrac Number # 

Methods

properFraction :: Integral b => Number -> (b, Number)

truncate :: Integral b => Number -> b

round :: Integral b => Number -> b

ceiling :: Integral b => Number -> b

floor :: Integral b => Number -> b

Show Number # 

Methods

showsPrec :: Int -> Number -> ShowS

show :: Number -> String

showList :: [Number] -> ShowS

data Text #

Instances

Eq Text # 

Methods

(==) :: Text -> Text -> Bool

(/=) :: Text -> Text -> Bool

Colors

newtype Color #

Constructors

RGBA (Number, Number, Number, Number) 

Instances

Eq Color # 

Methods

(==) :: Color -> Color -> Bool

(/=) :: Color -> Color -> Bool

type Colour = Color #

Pictures

type Point = (Number, Number) #

type Vector = (Number, Number) #

data Picture #

data TextStyle #

Constructors

Plain 
Italic 
Bold 

blank :: Picture #

A blank picture

path :: [Point] -> Picture #

A thin sequence of line segments with these endpoints

thickPath :: ([Point], Number) -> Picture #

A thin sequence of line segments, with these endpoints and line width

polygon :: [Point] -> Picture #

A thin polygon with these points as vertices

thickPolygon :: ([Point], Number) -> Picture #

A thin polygon with these points as vertices

solidPolygon :: [Point] -> Picture #

A solid polygon with these points as vertices

curve :: [Point] -> Picture #

A thin curve passing through these points.

thickCurve :: ([Point], Number) -> Picture #

A thick curve passing through these points, with this line width

loop :: [Point] -> Picture #

A thin closed loop passing through these points.

thickLoop :: ([Point], Number) -> Picture #

A thick closed loop passing through these points, with this line width.

solidLoop :: [Point] -> Picture #

A solid closed loop passing through these points.

rectangle :: (Number, Number) -> Picture #

A thin rectangle, with this width and height

solidRectangle :: (Number, Number) -> Picture #

A solid rectangle, with this width and height

thickRectangle :: (Number, Number, Number) -> Picture #

A thick rectangle, with this width and height and line width

circle :: Number -> Picture #

A thin circle, with this radius

solidCircle :: Number -> Picture #

A solid circle, with this radius

thickCircle :: (Number, Number) -> Picture #

A thick circle, with this radius and line width

arc :: (Number, Number, Number) -> Picture #

A thin arc, starting and ending at these angles, with this radius

sector :: (Number, Number, Number) -> Picture #

A solid sector of a circle (i.e., a pie slice) starting and ending at these angles, with this radius

thickArc :: (Number, Number, Number, Number) -> Picture #

A thick arc, starting and ending at these angles, with this radius and line width

text :: Text -> Picture #

A piece of text

styledText :: (Text, Font, TextStyle) -> Picture #

A styled piece of text

colored :: (Picture, Color) -> Picture #

A picture drawn entirely in this color.

coloured :: (Picture, Color) -> Picture #

A picture drawn entirely in this color.

translated :: (Picture, Number, Number) -> Picture #

A picture drawn translated in these directions.

scaled :: (Picture, Number, Number) -> Picture #

A picture scaled by these factors.

dilated :: (Picture, Number) -> Picture #

A picture scaled by these factors.

rotated :: (Picture, Number) -> Picture #

A picture rotated by this angle.

(&) :: Picture -> Picture -> Picture infixr 0 #

coordinatePlane :: Picture #

A coordinate plane. Adding this to your pictures can help you measure distances more accurately.

Example:

main = pictureOf(myPicture & coordinatePlane) myPicture = ...

:: Picture #

The CodeWorld logo.

Events

data Event #

An event initiated by the user.

Values of this type represent events that the user triggers when using an interaction, defined with interactionOf.

Key events describe the key as Text. Most keys are represented by a single character text string, with the capital letter or other symbol from the key. Keys that don't correspond to a single character use longer names from the following list. Keep in mind that not all of these keys appear on all keyboards.

  • Up, Down, Left, and Right for the cursor keys.
  • F1, F2, etc. for function keys.
  • Backspace
  • Tab
  • Enter
  • Shift
  • Ctrl
  • Alt
  • Esc
  • PageUp
  • PageDown
  • End
  • Home
  • Insert
  • Delete
  • CapsLock
  • NumLock
  • ScrollLock
  • PrintScreen
  • Break
  • Separator
  • Cancel
  • Help

Instances

Eq Event # 

Methods

(==) :: Event -> Event -> Bool

(/=) :: Event -> Event -> Bool

data MouseButton :: * #

Instances

Eq MouseButton 
Read MouseButton 

Methods

readsPrec :: Int -> ReadS MouseButton

readList :: ReadS [MouseButton]

readPrec :: ReadPrec MouseButton

readListPrec :: ReadPrec [MouseButton]

Show MouseButton 

Methods

showsPrec :: Int -> MouseButton -> ShowS

show :: MouseButton -> String

showList :: [MouseButton] -> ShowS

Debugging

traced :: (a, Text) -> a #

Entry points

type Program = IO () #

simulationOf :: ([Number] -> world, (world, Number) -> world, world -> Picture) -> Program #

interactionOf :: ([Number] -> world, (world, Number) -> world, (world, Event) -> world, world -> Picture) -> Program #

collaborationOf :: (Number, [Number] -> state, (state, Number) -> state, (state, Event, Number) -> state, (state, Number) -> Picture) -> Program #