Skip to content

Instantly share code, notes, and snippets.

Koz Ross kozross

Block or report user

Report or block kozross

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Patterns.hs
newtype Atom =
Atom Word64
preview :: Atom -> (Maybe Bool, Word64)
preview x =
let raw = coerce x
f = shorten raw
in if | testBit raw 63 -> (Nothing, f)
| testBit raw 62 -> (Just False, f)
| otherwise -> (Just True, f)
View Example.hs
newtype AtomP = AtomP Word64
view :: AtomP -> Maybe (Bool, Word64)
view x = let mask = complement (bit 63 .|. bit 62)
raw = coerce x in
if | testBit raw 63 -> Nothing
| testBit raw 62 -> Just (False, pext64 raw mask)
| otherwise -> Just (True, pext64 raw mask)
-- I want to expose a view of AtomP as a Maybe (Bool, Word64) on the basis of the function above.
View Example.hs
-- Suppose these are the mappings:
mappingsAsList :: [((Int,Int), Bool)]
mappingsAsList [((1,2), True), ((1,3), False), ((1,4), True),
((2,4), True), ((2,5), False), ((2,6), True)]
-- I wanna be able to efficiently request 'give me all mappings where the first part of the key is x'.
-- For instance, if I asked for x = 1, I should get [((1,2), True), ((1,3), False), ((1,4), True)]
-- I also wanna be able to efficiently request 'give me all mappings where the second part of the key is y'.
-- For instance, if I asked for y = 4, I should get [((1,4), True), ((2,4), True)]
View Data.Massiv.Array.Sized.One.hs
{-# LANGUAGE DataKinds, DeriveFunctor, GADTs, KindSignatures,
ScopedTypeVariables, TemplateHaskell, TypeFamilies,
TypeApplications #-}
module Data.Massiv.Array.Sized.One where
import CoercibleUtils
import Data.Coerce
import Data.Finite
import Data.Foldable
View Family.hs
import qualified Data.Vector.Unboxed as V
data Categorical = -- some definition of a type here
data Discrete = -- some definition of a type here
data Continuous = -- some definition of a type here
type family ColumnData a where
ColumnData Categorical = V.Vector Word32
View CRLF.hs
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
module Data.CRLF where
import GHC.Generics
import Control.Monad.Except
import Data.Binary
View why-this-break.jl
arr = [5, 8, 11, 0]
function bitat(x,i)
x & (1 << (i - 1)) != 0
end
y = BitMatrix(bitat(arr[i], j) for i in 1:4, j in 1:4)
#=
This fails, claiming:
MethodError: Cannot `convert` an object of type Base.Generator{Base.Iterators.Prod2{UnitRange{Int64},UnitRange{Int64}},##9#10} to an object of type BitArray{2}
@kozross
kozross / .nvimrc
Created Dec 13, 2017
Haskell setup
View .nvimrc
augroup ghciMaps
au!
au FileType haskell nnoremap <silent> <leader>gs :GhciStart<CR>
au FileType haskell nnoremap <silent> <leader>gk :GhciKill<CR>
au FileType haskell nnoremap <silent> <leader>gr :GhciRestart<CR>
au FileType haskell nnoremap <silent> <leader>go :GhciOpen<CR>
au BufWritePost *.hs GhciReload
au BufWritePost *.hs GhciReload
let g:ghci_command = 'stack repl'
let g:ghci_command_line_options = '--ghci-options="-fobject-code -Wall"'
View my-sql-issue.sql
-- I'm trying to write up a schema for an SQLite database storing some data sets
-- Requirements are as follows:
-- 1) Every data set has a unique name
-- 2) Every data set has multiple attributes associated with it
-- 3) Every attribute has several possible values
-- 4) Attributes may be class attributes or non-class attributes
-- 5) Every record is associated with one data set
-- 6) Every record must have exactly one value for every attribute associated with its data set
--
-- Now, I can get as far as point 4 with the following:
View error.tex
! You can't use `\prevdepth' in horizontal mode.
\nointerlineskip ->\prevdepth
-\@m \p@
l.286 \end{slide}
You can’t perform that action at this time.