Skip to content

Instantly share code, notes, and snippets.

View ramirez7's full-sized avatar
๐Ÿ’—
Grey hairs are visible / I'm kinda of miserable, too

Armando Ramirez ramirez7

๐Ÿ’—
Grey hairs are visible / I'm kinda of miserable, too
View GitHub Profile
module FizzBuzzC
%default total
-- Dependently typed FizzBuzz, constructively
-- A number is fizzy if it is evenly divisible by 3
data Fizzy : Nat -> Type where
ZeroFizzy : Fizzy 0
Fizz : Fizzy n -> Fizzy (3 + n)
@ramirez7
ramirez7 / hlist.idr
Created September 6, 2015 03:42
HList take
module HList
% default total
data HList : List Type -> Type where
HNil : HList []
(::) : t -> HList ts -> HList (t :: ts)
hcons : t -> HList ts -> HList (t :: ts)
hcons = (::)
-- map is my original implementation
map : (f ~~> g) -> HList ts -> {auto prf : Mapper (f ~~> g) ts ts'} -> HList ts'
map f xs {prf} = map' f xs prf
-- It works for mapping head' over an HList of Lists:
:let xs: HList[List Int, List Bool]; xs = [[2], [True]]
*hlist> :let xs: HList[List Int, List Bool]; xs = [[2], [True]]
*hlist> :let ys2: HList[Maybe Int, Maybe Bool]; ys2=map (MkPoly(\a => head'{a=a})) xs
*hlist> ys2
[Just 2, Just True] : HList [Maybe Int, Maybe Bool]
import scalaz._, Scalaz._, \&/.{Both, This, That}
object TheseUtils {
// For reference:
// sealed trait \&/[+A, +B]
// case class This[A](aa: A) extends (A \&/ Nothing)
// case class That[B](bb: B) extends (Nothing \&/ B)
// case class Both[A, B](aa: A, bb: B) extends (A \&/ B)
// smart constructors
import shapeless._
sealed trait SetBy[A, B, FT <: A => B] {
def +(a: A): SetBy[A, B, FT]
def values: Set[A]
override def toString: String = s"SetBy(${values.mkString(", ")})"
}
object SetBy {
import shapeless._
import org.joda.time.{DateTime, DateTimeZone}
sealed abstract class Zoned[Z <: DateTimeZone] {
def dt: DateTime
override def toString: String = dt.toString
}
object Zoned {
private case class zonedImpl[Z <: DateTimeZone](dt: DateTime) extends Zoned[Z]
def apply[Z <: DateTimeZone](dt: DateTime)(implicit w: Witness.Aux[Z]): Option[Zoned[Z]] = {
import shapeless._
import shapeless.record._
import shapeless.ops.hlist.Mapper
import shapeless.ops.hlist.ToTraversable
import shapeless.ops.record.{Keys, Fields}
import org.joda.time.format.DateTimeFormatter
import org.joda.time.LocalDate
object ShapelessCsv {
type UnitTest a = S.StateT Bool IO a
test :: (Show a, Eq a) => String -> a -> a -> UnitTest ()
test name found expected
| found == expected = passTest
| otherwise = failTest
where
failTest = (S.put True) >> S.liftIO (testStrLn (printf "[FAILED] \"%s\"; Found { %s } ; Expected { %s }" name (show found) (show expected)))
passTest = S.liftIO (testStrLn (printf "[PASSED] \"%s\"" name))
runTests :: [UnitTest a] -> IO ()

config file:

cfg {
  list_of_lists = [["a", "b"], ["$(THE_X)", "$(THE_Y)"]]
  other_list = ["$(THE_X)", "$(THE_Y)"]
  x = "$(THE_X)"
  y = "$(THE_Y)"
}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}