Skip to content

Instantly share code, notes, and snippets.

@leon-vv
Created January 18, 2018 16:26
Show Gist options
  • Save leon-vv/a8e6b59ef062dd0fe5afadb41d0920f2 to your computer and use it in GitHub Desktop.
Save leon-vv/a8e6b59ef062dd0fe5afadb41d0920f2 to your computer and use it in GitHub Desktop.
Idris node codegen bug (Can't happen pickAlt - impossible case found)
import IdrisScript
Schema : Type
Schema = List (String, Type)
-- First class record
data Record : Schema -> Type where
RecNil : Record Nil
RecCons : (key:String) -> (val : t) -> Record lst -> Record ((key, t)::lst)
data Useless : Type where I : Useless
-- The type at the given key in a schema
typeAtKey : Schema -> String -> Type
typeAtKey Nil _ = Useless
typeAtKey ((k', t)::rest) k = if (k' == k) then t else (typeAtKey rest k)
-- Access a field of a record
access : Record keyMap -> (k : String) -> typeAtKey keyMap k
access RecNil k = I
access (RecCons key val rest) k with (key == k)
| True = val
| False = access rest k
refToRecords : JSRef -> JS_IO (Maybe (Int))
refToRecords ref = do
packed <- pack ref
pure Nothing
toRecord : Record [("rows", JSRef)] -> JS_IO Int
toRecord rec = believe_me (refToRecords (access rec "rows"))
mapIO : (a -> JS_IO b) -> JS_IO (Maybe a) -> JS_IO (Maybe b)
mapIO f ev = ev >>= (believe_me () . map f)
runSelectQuery : JS_IO (JS_IO (Maybe (Int)))
runSelectQuery = pure (mapIO toRecord (believe_me ()))
main : JS_IO ()
main = do
runSelectQuery
pure ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment