Skip to content

Instantly share code, notes, and snippets.

View kritzcreek's full-sized avatar

Christoph Hegemann kritzcreek

View GitHub Profile
@kritzcreek
kritzcreek / Main.purs
Last active March 6, 2016 15:36
Space Invader
module Main where
import Prelude
import Data.Array ((..), length, head, zip)
import Data.Foldable (fold, foldMap)
import Data.Int (toNumber)
import Data.Maybe (Maybe(Just), maybe)
import Data.Monoid (mempty)
import Data.String as S
@kritzcreek
kritzcreek / Post.md
Last active January 20, 2019 22:42
Teaching Polymorphism

"Is Haskell a good first programming language?"

This question was asked at the recent HaskellX conference, with both practicioners as well as teachers being present. I won't reiterate everything that was said, and instead link to a recording of the podium discussion (https://skillsmatter.com/skillscasts/10952-park-bench-panel-session-with-haskellx-experts).

One particular argument, that I've heard come up multiple times now, is that teachers are complaining about the length function being polymorphic. Apparently length :: forall a. Foldable f => f a -> Int is hard to grasp/understand/accept for a new-comer. The solutions proposed to solve this problem are to:

  1. Return length to its non-Foldable type
  2. Use a custom Prelude to teach beginners

Drawbacks for 1 include that practicioners like the fact that length works for all kinds of data structures, and don't want that taken away from them. The primary problem with solution 2 is that students can't go and use their aquired knowledge to work on Open

@kritzcreek
kritzcreek / Main.purs
Created March 1, 2020 18:56
Set Interval in PureScript
module Main where
import Prelude
import Data.Maybe (Maybe(..))
import Effect (Effect)
import Effect.Console (log)
import Effect.Random as Random
import Effect.Ref as Ref
import Effect.Timer (clearInterval, setInterval)
module Sexp.Codec
( SexpDecodeError(..)
, sexp
, boolean
, number
, int
, string
, array
) where
@kritzcreek
kritzcreek / File.purs
Last active March 12, 2020 12:30
Purescript - Read a file from disc with the browser API
import Control.Monad.Aff (Aff, Canceler(..), makeAff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Exception (error)
import DOM (DOM)
import DOM.Event.EventTarget (addEventListener, eventListener, removeEventListener)
import DOM.File.FileReader as FR
import DOM.File.Types (Blob, fileReaderToEventTarget)
import DOM.HTML.Event.EventTypes as Events
import Data.Foreign (readString)
@kritzcreek
kritzcreek / Kinds-and-do-syntax.md
Last active March 28, 2020 11:51
Kinds and Do-Syntax

Kinds

In PureScript there are types of different kinds. Kinds are types for types. For example Int has kind Type, and we write it as Int :: Type. You can ask for the kind of a type in purs psci

> :k Int
Type

Type constructors take types to other types. For example Array (which still needs another type to form a type a value could have, like Array Int):

import Prelude
import Control.Monad
import Data.Foldable
import Language.PureScript.CST.Types as CST
import Language.PureScript.CST.Parser as CST
import Language.PureScript.CST.Print as CST
import Data.Text (Text)
import Data.Text.IO as Text
import System.Directory
import System.FilePath
module Main where
import Prelude
import Data.Map as Map
import Data.Tuple (Tuple(..))
myMap :: Map.Map Int String
myMap = Map.fromFoldable [Tuple 1 "Hi"]
module Main where
import Prelude
import Data.Maybe
mystery :: forall a b. (a -> Maybe b) -> Array a -> Array b
mystery = ?x
[
{
name = "base",
repo = "https://github.com/dfinity/motoko-base",
version = "dfx-0.5.13",
dependencies = [] : List Text
}
]