Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE PolyKinds, DataKinds, TypeApplications, TypeOperators, KindSignatures, GADTs, TypeFamilies, ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
-- ^ more extensions might be needed to do what I want to do, idk
-- Defunctionalized higher-order data constructors--are they possible?
module DefunHigherDataCons where
import Data.Kind
import Data.Singletons.TH
@greatBigDot
greatBigDot / Matrix.hs
Last active February 22, 2020 03:53
Types of dimension-indexed matrices in Haskell.
{-# LANGUAGE UnicodeSyntax, NoStarIsType #-}
{-# LANGUAGE GADTs, DataKinds, PolyKinds, PatternSynonyms, ViewPatterns, TypeApplications #-}
module Data.Matrix where
import Data.Kind
-- The usual definitions of Nat and Vec:
data Nat = Z | S Nat
@greatBigDot
greatBigDot / Utils.hs
Last active February 22, 2020 03:48
Natural numbers and vectors and such
{-# LANGUAGE UnicodeSyntax, NoStarIsType, LambdaCase #-}
{-# LANGUAGE GADTs, DataKinds, PolyKinds, PatternSynonyms, ViewPatterns, TypeApplications #-}
module Utils where
import Data.Kind
-- The usual definitions of Nat and Vec:
data Nat = Z | S Nat
@greatBigDot
greatBigDot / InvalidInference.hs
Last active June 2, 2019 03:28
Inferred type is invalid
{-# LANGUAGE AllowAmbiguousTypes, MultiParamTypeClasses, NoMonomorphismRestriction #-}
module InvalidInference where
class Foo s t where
foo :: t
-- When commented, GHCi infers this type; when uncommented, it yields a type error:
-- bar :: Foo s t => t
bar = foo
@greatBigDot
greatBigDot / Implicit.hs
Last active April 10, 2019 04:58
A failed attempt to represent implicit proof terms in quasi-dependent Haskell.
{-# LANGUAGE LambdaCase, EmptyCase
, EmptyDataDecls, TypeOperators, LiberalTypeSynonyms,
ExistentialQuantification, GADTSyntax, GADTs
, StandaloneDeriving
, InstanceSigs, FlexibleContexts, MultiParamTypeClasses,
FlexibleInstances , TypeSynonymInstances , FunctionalDependencies
, TypeFamilies, TypeFamilyDependencies, DataKinds, PolyKinds,
@greatBigDot
greatBigDot / 4SWC.agda
Last active December 7, 2018 17:15
A constructive proof that there is no largest natural number, from scratch.
-- A constructive proof that there is no biggest natural. I.e., we construct the
-- type "there is no biggest natural" and construct an element of it. The
-- naturals, the order relation on them, etc. are likewise all defined
-- constructively.
module 4SWC where
-- Just to take care of the universe levels; you can safely ignore it:
open import Agda.Primitive
@greatBigDot
greatBigDot / bash-funcname-weirdness
Last active November 8, 2018 06:22
The builtin array variable 'FUNCNAME' is considered unset by many expansions, even when set. Bash bug?
#!/bin/bash
set +eu
# # Uncomment this to see what a normal array would do:
# array=( "${FUNCNAME[@]}" )
# unset FUNCNAME
# FUNCNAME=( "${array[@]}" )
# unset array
# # Or uncomment this for the same result in a more direct fashion:
@greatBigDot
greatBigDot / Field.hs
Last active August 10, 2018 16:56
An attempt to understand Haskell's various ways to get a partially-collapsed type hierarchy and partially-dependent types, via algebraic structures implemented as typeclasses.
{-# LANGUAGE EmptyDataDecls, TypeOperators, LiberalTypeSynonyms, ExistentialQuantification, ExplicitForAll #-}
{-# LANGUAGE GADTSyntax, GADTs, DuplicateRecordFields, NamedFieldPuns, MultiParamTypeClasses, FlexibleContexts, TypeSynonymInstances, FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies, TypeFamilies, TypeFamilyDependencies, ConstraintKinds, ScopedTypeVariables #-}
{-# LANGUAGE DataKinds, PolyKinds, KindSignatures, TypeInType, TypeApplications, ImplicitParams, NamedWildCards, RankNTypes #-}
{-# LANGUAGE ExplicitNamespaces, MonoLocalBinds, DisambiguateRecordFields, ConstrainedClassMethods #-}
--- ^ I just grabbed anything that looked remotely useful.
module Algebraics.Data.Field where
import GHC.TypeLits
<interactive>:1:6: error:
Not in scope: ‘System.IO.hSetBuffering’
No module named ‘System.IO’ is imported.
<interactive>:1:30: error:
Not in scope: ‘System.IO.stdin’
No module named ‘System.IO’ is imported.
<interactive>:1:46: error:
Not in scope: data constructor ‘System.IO.NoBuffering’