Skip to content

Instantly share code, notes, and snippets.

extension Vector2D: Field {}
@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)
@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 / 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|
%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
-- as long as there is a proof that a < b then we can build a Fin b
natToProvedFin : (n : Nat) -> (bound : Nat) -> {auto prf : LT n bound} -> Fin bound
natToProvedFin Z (S right) {prf=LTESucc x} = FZ
natToProvedFin (S k) (S right) {prf=LTESucc x} = FS $ natToProvedFin k right
record Numbers where
constructor MkNumbers
max : Nat
bonus : Nat
current : Fin (S (max + bonus))
@andrevidela
andrevidela / ex_13_1_2.idr
Created August 17, 2017 22:24
Can't infer explicit argument to tryGenOp, Can't infer explicit argument to S, Can't infer explicit argument to doAdd
mutual
tryGenOp : StackCmd () pre (S _) -> StackIO h
tryGenOp x {pre} {h} = case decEq pre h of
(Yes Refl) => do x
res <- Top
PutStr (show res ++ "\n")
stackCalc
(No contra) => do PutStr $ "not enough item on the stack, expected " ++
/// Partially applies the right argument of a binary function
func partialRightApply<A, B, C>(_ f: @escaping (A, B) -> C, arg rhs: B) -> (A) -> C {
return {lhs in f(lhs, rhs)}
}
prefix operator >
prefix func > <T: Comparable>(rhs: T) -> (T) -> Bool {
return partialRightApply(>, arg: rhs)
}
prefix operator ==
prefix func == <T: Equatable>(rhs: T) -> (T) -> Bool {
return { lhs in lhs == rhs }
}
infix operator •
public func • <A, B, C>(f : @escaping (B) -> C, g : @escaping (A) -> B) -> (A) -> C {
return { f(g($0)) }
}