Skip to content

Instantly share code, notes, and snippets.

@laughedelic
laughedelic / TH+SYB_substNames.hs
Created November 1, 2011 23:29
Names substitution in declaration templates (TH + SYB)
{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH
import Language.Haskell.TH.Lib hiding (rename)
import Control.Monad (liftM)
import Data.List (lookup)
import Data.Generics.Aliases (mkT)
import Data.Generics.Schemes (everywhere)
----------------------------------------------------------------
@laughedelic
laughedelic / Printf.hs
Created November 15, 2011 20:33
printf с помощью Template Haskell
{-# LANGUAGE TemplateHaskell #-}
module Printf (printf) where
-- Импортируем инструментарий Template Haskell
import Language.Haskell.TH
-- | Шаблон для функции printf
-- Пример использования:
-- > putStrLn ( $(printf "Number %d is %s of %d.") 327 "square" (327^2) )
@laughedelic
laughedelic / Prolog.hs
Created December 1, 2011 15:32 — forked from hodzanassredin/Prolog.hs
simple type level predicates in haskell (with functional dependencies)
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, UndecidableInstances #-}
module Prolog (Petja, Vasja, Serg, Father, Son, GrandFather) where
data Petja = Petja
data Vasja = Vasja
data Serg = Serg
@laughedelic
laughedelic / DecemberFair.hs
Created December 2, 2011 19:05
Solution for december FP fair
module DecemberFair where
import Data.Maybe (listToMaybe)
import Data.List (permutations, nubBy)
-- only non-symetric permutations
permute :: (Eq a) => [a] -> [[a]]
permute = nubBy (\ys zs -> ys == (reverse zs)) . permutations
-- binary operators
@laughedelic
laughedelic / g8test.sh
Last active December 11, 2015 09:58
Simple script for testing g8 templates without giter8 sbt-plugin (because it's weird). See instructions in comments.
# assuming that this script lies in g8test/ folder of the root directory of a g8-template
cd g8test
g8 file://.. --name=template > /dev/null
echo "Template applied in g8test/template/"
cd template
echo "sbt test:" && sbt test
cd ../..
@laughedelic
laughedelic / symbol-list-tester.cs
Created January 28, 2013 00:20
file that I used to test C# Sublime plugin indentation in Symbol List: https://github.com/laughedelic/SublimeCSharp
namespace FooNamespace
{
class Class
{
static void Method1(){}
static void Method2(){}
class InnerClass
{
static void InnerMethod1(){}
@laughedelic
laughedelic / gist:5444351
Created April 23, 2013 15:06
Workaround for using scala 2.10 in conscript app
[app]
...
name: foo_2.10
cross-versioned: false
[scala]
version: 2.10.0
@laughedelic
laughedelic / UnionHList.scala
Created October 3, 2013 10:55
Constructing union type from an HList
trait UnionOf[L <: HList] {
type Mix
type Out = not[Mix]
type is[O] = UnionAux[L, O]
}
/* Implicits for constructing union: */
object UnionOf {
implicit val nil =
new UnionOf[HNil] { type Mix = not[Nothing] }
@laughedelic
laughedelic / HListSubtract.scala
Created October 4, 2013 08:32
Using union for subtracting HLists (i.e. filtering first one using second as the reference of unwanted types). See also https://gist.github.com/laughedelic/6808000 for the union construction.
object HListSubtract {
// We use here this construction: https://gist.github.com/laughedelic/6808000
import UnionHList._
// Filters an HList `L`, trowing away any elements, that are in the given union `U`
trait Filter[L <: HList, U] {
type Out <: HList
def apply(l: L): Out
}
@laughedelic
laughedelic / taglistSettings.scala
Created November 11, 2013 11:47
sbt-taglist plugin settings
lazy val tagListSettings: Seq[Setting[_]] =
TagListPlugin.tagListSettings ++ Seq(
TagListKeys.tags := Set(
TagListPlugin.Tag("todo", TagListPlugin.Warn)
, TagListPlugin.Tag("fixme", TagListPlugin.Error)
)
)