Day 65 - My Haskell Genesis

November 8, 2018
Haskell IO do

Today I made my first Haskell Project !

It was a text-based hangman game, and it was heavily guided by the book, even-so it brought everything together and it was quite cool actually producing something tangible.

So the basics for setting up any project is by the following commands:

stack new my-project
cd my-project
stack setup
stack build
stack exec my-project-exe

The .cabal file

This file is a file in the project directory to document build and library dependencies and write executables. By using the stack build commands above, a pre-configured .config file is created.

Basic terms to know pre-monad enlightenment

IO

As touched upon in previous blogs, the IO (Input/Output) type is used to control side effects and keep them explicitly separate to other types. methods that inherit the IO typeclass are usually defined as a Unary constructer with a Type signature of IO a which when used with a binding <- becomes type a (binding is a way of equally the output of a IO a method to a value of type a (this is very simplified, as I do not yet understand Monads).

do

do is syntactic sugar to sequentially order function calls. They make things more readable by explicitly showing in what order things are being called.

The main function is the one that usually needs to introduce side effects, by either pulling data or reading from the console. Therefore it is usually the case that this would be a do block of type IO

main :: IO ()
main = do
  name <- getLine
  return name

Key bits

To make import aliases: import qualified Data.Bool as B

return, returns a monad value in IO. Without it, the value would not be returned.

forever, from the Control.Monad library allows the creation of an infinite loop, analogous to a While loop.

exitSuccess from the System.Exit library is a safe way to exit the programme.

Day 107 - What do you call a typeclass from the 80's?

December 18, 2018
Haskell Functors

Day 102 - Katas but not yet Functors

December 14, 2018
Haskell Kata

Day 98 - ToDo List ft. Functor/Applicative

December 10, 2018
Haskell Testing
comments powered by Disqus