packages feed

purescript-0.8.1.0: examples/passing/DctorOperatorAlias.purs

module Data.List where

  data List a = Cons a (List a) | Nil

  infixr 6 Cons as :

module Main where

  import Prelude (Unit, bind, (==))
  import Control.Monad.Eff (Eff)
  import Control.Monad.Eff.Console (CONSOLE, log)
  import Test.Assert (ASSERT, assert')
  import Data.List (List(..), (:))

  infixl 6 Cons as !

  get1 ∷ ∀ a. a → List a → a
  get1 y xs = case xs of
    _ : x : _ → x
    _ → y

  get2 ∷ ∀ a. a → List a → a
  get2 _ (_ : x : _) = x
  get2 y _ = y

  get3 ∷ ∀ a. a → List a → a
  get3 _ (_ ! (x ! _)) = x
  get3 y _ = y

  main ∷ Eff (assert ∷ ASSERT, console ∷ CONSOLE) Unit
  main = do
    assert' "Incorrect result!" (get1 0 (1 : 2 : 3 : Nil) == 2)
    assert' "Incorrect result!" (get2 0 (1 ! (2 ! (3 ! Nil))) == 2)
    assert' "Incorrect result!" (get3 0.0 (1.0 : 2.0 : (3.0 ! Nil)) == 2.0)
    log "Done"