Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View gustavofranke's full-sized avatar

Gustavo Franke gustavofranke

View GitHub Profile
package option
import org.scalatest.funsuite.AnyFunSuite
/**
* show some scala language features that, if you come from other languages, they might be unknown to you.
*
* Like last week, we'll play with the REPL, then turn our findings into tests.
*
* I'll use scala-test to automate this process,
module Geometry.Cube
( volume
, area
) where
import qualified Geometry.Cuboid as Cuboid
volume :: Float -> Float
volume side = Cuboid.volume side side side
Data.Time> :t "foo"
"foo" :: [Char]
Data.Time> :set -XOverloadedStrings
Data.Time> :t "foo" "foo" :: Data.String.IsString p => p
-- stack repl --package <package-name>
-- stack repl --package time
> import Data.Time
Data.Time> getCurrentTime
2020-10-17 15:03:15.521782 UTC
Data.Time> utctDay <$> getCurrentTime
2020-10-17
Data.Time> today <- utctDay <$> getCurrentTime
Data.Time> today
package cipher
def lowers(xs: String): Int =
xs.filter(x => x >= 'a' && x <= 'z').length
def count(x: Char, xs: String): Int =
xs.toList.filter(x0 => x == x0).length
def positions[A](x: A, xs: List[A]): List[Int] =
for
package playground
// https://www.youtube.com/watch?v=xpz4rf1RS8c
// 01. functional effects
// Console - Model 1
sealed trait Console1 { self =>
def +(that: Console1): Console1 = Sequence1(self, that)
}
final case class Print1(line: String) extends Console1
final case class Sequence1(first: Console1, second: Console1) extends Console1
@gustavofranke
gustavofranke / exercises.hs
Last active April 11, 2020 11:19
first chapters sample code
-- 1.7Exercises
-- 1.Give another possible calculation for the result of double (double 2).
double x = x + x
another = (double . double) 2
-- 2.Show that sum [x] = x for any number x.
ex2 :: (Eq a, Num a) => a -> Bool
ex2 x = sum [x] == x
@gustavofranke
gustavofranke / write-you-a-scheme.hs
Created February 17, 2020 12:57
first part of chapter 5
module Main where
import Control.Monad
import Control.Monad.Except
import System.Environment
import Text.ParserCombinators.Parsec hiding (spaces)
main :: IO ()
main = do
args <- getArgs
evaled <- return $ liftM show $ readExpr (args !! 0) >>= eval
@gustavofranke
gustavofranke / Database.hs
Last active February 6, 2020 23:12
Domain Modelling with Haskell: Data Structures - from https://www.youtube.com/watch?v=pe6S5skZwNE
module Database where
import System.Random (getStdRandom, randomR)
import Project
getBudget :: ProjectId -> IO Budget
getBudget _ = do
income <- Money <$> getStdRandom (randomR (0, 10000))
expenditure <- Money <$> getStdRandom (randomR (0, 10000))
pure Budget { budgetIncome = income, budgetExpenditure = expenditure}
-- from
-- https://www.youtube.com/watch?v=lxjIUWGMUqE
-- Haskell at Work - Validation with Smart Constructors
module SerialNumber
( SerialNumber
, ValidataionError(..)
, makeSerialNumber
, renderSerialNumber
) where