Skip to content

Instantly share code, notes, and snippets.

@bkyrlach
Created November 13, 2018 20:59
Show Gist options
  • Select an option

  • Save bkyrlach/514586abb7882ffc749e6dbd7acc7e17 to your computer and use it in GitHub Desktop.

Select an option

Save bkyrlach/514586abb7882ffc749e6dbd7acc7e17 to your computer and use it in GitHub Desktop.
module Intro where
import Data.Char (toUpper)
x = 3
greeting = "Hello"
three :: () -> Int
three _ = 3
y = three ()
square (n) = n * n
greet name = greeting ++ ", " ++ name ++ "!"
add (x,y) = x + y
mult (x,y) = x * y
sumit ([]) = 0
sumit ((h:t)) = add (h,sumit (t))
prod ([]) = 1
prod ((h:t)) = mult (h,prod (t))
flerf (base, f, []) = base
flerf (base, f, (h:t)) = f (h, flerf (base, f, t))
power (xs) = flerf (1, (\(x,y) -> x^y), xs)
add' :: Int -> Int -> Int
add' x y = x + y
chickenCurry :: ((a,b) -> c) -> a -> b -> c
chickenCurry f = (\a -> \b -> f (a,b))
add'' = chickenCurry add
flerf' base f [] = base
flerf' base f (h:t) = f h $ flerf' base f t
power' = flerf' 1 (^)
mapit f [] = []
mapit f (h:t) = (f h):(mapit f t)
shout s = mapit toUpper s
shoutAGreeting = shout . greet
greetByShoutingName = greet . shout
data Color = Red | Green | Blue
colorToString Red = "Red"
colorToString Green = "Green"
colorToString Blue = "Blue"
data Color' = Red' | Green' | Blue' deriving (Show)
data Tree a =
| Branch Tree a Tree
| Leaf
deriving (Show)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment