Skip to content

Instantly share code, notes, and snippets.

%default total
data Prop = Var String
| Not Prop
| And Prop Prop
| Or Prop Prop
| Impl Prop Prop
| Equiv Prop Prop
data Lit = Stmt String | Neg String
@andrevidela
andrevidela / gist:2c551fad7e58713d0e082d2964b7db1f
Created September 5, 2018 07:22
custom primary key persistent
atlantis-db/src/Atlantis/Database/Entities.hs:35:1: error:
• No instance for (Read Hash)
arising from the first field of ‘TransactionEntityKey’
(type ‘Hash’)
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
• When deriving the instance for (Read (Key TransactionEntity))
|
35 | share [mkPersist sqlSettings, mkMigrate "migrateTables"] [persistLowerCase|
@andrevidela
andrevidela / gist:db830623c851d4ebb9e6c57ad1490982
Created September 5, 2018 07:22
custom primary key persistent
atlantis-db/src/Atlantis/Database/Entities.hs:35:1: error:
• No instance for (Read Hash)
arising from the first field of ‘TransactionEntityKey’
(type ‘Hash’)
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
• When deriving the instance for (Read (Key TransactionEntity))
|
35 | share [mkPersist sqlSettings, mkMigrate "migrateTables"] [persistLowerCase|
@andrevidela
andrevidela / dependent-typeclass.hs
Last active December 11, 2018 23:00
How to select the correct instance for an indexed typeclass?
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables#-}
{-# LANGUAGE TypeApplications#-}
{-# LANGUAGE TypeFamilies #-}
data ValueKind = First | Second deriving (Eq, Show)
extension Vector2D: Field {}
/// Protocol for addition with identity
protocol Additive {
static var addId: Self { get }
static func + (_ lhs: Self, _ rhs: Self) -> Self
}
// Ints are Multiplicative, the identity is 1
extension Int: Multiplicative {
static var multId: Int {
return 1
}
}
// Ints are Additive, the identity is 0
extension Int: Additive {
static var addId: Int { return 0 }
}
/// Protocol for 2D coordinate systems
protocol TwoDimensions {
associatedtype ComponentVal
static func make2D(_ fst: ComponentVal, _ snd: ComponentVal) -> Self
var fst: ComponentVal { get } // The first component
var snd: ComponentVal { get } // The second component
}
/// Protocol for multiplication with identity
protocol Multiplicative {
static var multId: Self { get }
static func * (_ lhs: Self, _ rhs: Self) -> Self
}