3. Working with the Steppable Prelude

The Haskell Substitution Stepper allows you to work with your own expressions, types and type classes. But sometimes, it is tiring to write everything by yourself. The Haskell Standard Prelude already has many useful types, type classes and functions implemented.

The Haskell Substitution Stepper does not (yet) support input files that import other files. To avoid the implicit import of the standard Haskell Prelude, the following option should be added to every import file:

{-# OPTIONS -XNoImplicitPrelude #-}

However, the stepper comes with a custom implementation of the Prelude that contains almost everything from the original Prelude (except functions and types that work with IO, Read or Show).

The file SteppablePrelude.hs can be downloaded here.

To work with the steppable prelude, the input file should look like this:

{-# OPTIONS -XNoImplicitPrelude #-}

module Input where

import SteppablePrelude

--add your expressions here

You can now write expressions using the functions, types and type classes from the SteppablePrelude. Here are some valid expressions that you could write:

 fmap even (Just 42)
foldl (+) 0 [1, 2, 3]  
lookup "EN" [("EN", "Hello World"), ("DE", "Hallo Welt")]
zip [1, 2, 3] [4, 5, 6]

You can also work with the standard type classes. For example:

data Direction a = Top a | Down a deriving (Ord, Eq)

Please note, that the import of the SteppablePrelude is just there to prevent your IDE from showing errors when you create your input file for the stepper. The stepper actually ignores the import statement and uses the SteppablePrelude that is hardcoded into the stepper executable. This means that modifying the Prelude file does not have any effect on the stepper itself. If you want to create your own functions, type or typeclasses, do it directly in the Input-file itself.

Some type class instances or functions from the original Haskell Prelude cannot be implemented in Haskell code itself, and thus are not part of the HaskellPrelude.hs file. Those type class instances and functions are implemented directly into the backend of the stepper and can be used like any other type class or function. For example, you can write sin 0.3, even though this function is only referenced in the steppable prelude but not implemented.

Next Chapter

Previous Chapter