Skip to content

Instantly share code, notes, and snippets.

View kcsongor's full-sized avatar
🤡
':<>:

Csongor Kiss kcsongor

🤡
':<>:
View GitHub Profile
type family RowToList (r :: * -> *) :: [(Symbol, *)] where
RowToList (l :*: r)
= Merge (RowToList l) (RowToList r)
RowToList (S1 ('MetaSel ('Just name) _ _ _) (Rec0 a))
= '[ '(name, a)]
RowToList (M1 _ m a)
= RowToList a
RowToList _
= '[]
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Overlapping where
class C a b where
f :: a -> b -> Bool
instance C a b where
f _ _ = False
@kcsongor
kcsongor / natty.hs
Created October 16, 2017 11:55
natty
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
import Control.Lens
--------------------------------------------------------------------------------
@kcsongor
kcsongor / kindclass.hs
Last active December 3, 2017 22:16
some kind classes
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
-- (some examples at the bottom)
import Data.Kind (Constraint, Type)
import GHC.TypeLits (Nat, type (+), type (*))
@kcsongor
kcsongor / RowToList-tf.hs
Created September 11, 2017 17:03
RowToList with type families
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
object Main {
/*
* First thing first, we turn on a ("advanced") language feature via
* `import scala.language.higherKinds`
*
* This is so that we can express higher-kinded types (HKTs) in generic
* parameters. Comes in handy for `Functor`, as all functors are HKTs, and
* also for `Fix`, for similar reasons.
*
@kcsongor
kcsongor / Tuples.hs
Created June 13, 2017 10:38
Extensible tuples
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeOperators #-}
@kcsongor
kcsongor / generic-encode.hs
Created January 23, 2017 17:45
Generic encoding
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}