Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Mar 28, 2024
2 parents bdf115f + 9b60590 commit e0feab0
Show file tree
Hide file tree
Showing 128 changed files with 2,633 additions and 87 deletions.
15 changes: 14 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3649,4 +3649,17 @@
url = https://github.com/engstrand-config/guix-dotfiles
[submodule "2024/03/26/pick-up-nix"]
path = 2024/03/26/pick-up-nix
url = https://github.com/jmikedupont2/pick-up-nix.git
url = https://github.com/jmikedupont2/pick-up-nix
[submodule "2024/03/27/hivemind"]
path = 2024/03/27/hivemind
url = https://github.com/learning-at-home/hivemind

[submodule "2024/03/27/swarm"]
path = 2024/03/27/swarm
url = https://github.com/yandex-research/swarm
[submodule "2024/03/27/petals-api"]
path = 2024/03/27/petals-api
url = https://huggingface.co/spaces/bigscience/petals-api
[submodule "2024/03/27/peft"]
path = 2024/03/27/peft
url = https://github.com/huggingface/peft
18 changes: 18 additions & 0 deletions 2023/06/26/test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

{-# LANGUAGE TemplateHaskell #-}

import Language.Haskell.TH
import Language.Haskell.TH.Syntax

listMembers :: Q [Dec]
listMembers = do
info <- reify (mkName "Language.Haskell.TH.Syntax")
case info of
TyConI (DataD _ _ _ _ constructors _) -> return constructors
_ -> fail "Invalid type"

main :: IO ()
main = do
members <- runQ listMembers
putStrLn "Members:"
mapM_ (putStrLn . pprint) members
Binary file added 2023/06/26/test2
Binary file not shown.
Binary file added 2023/06/26/test2.dyn_hi
Binary file not shown.
Binary file added 2023/06/26/test2.dyn_o
Binary file not shown.
Binary file added 2023/06/26/test2.hi
Binary file not shown.
17 changes: 17 additions & 0 deletions 2023/06/26/test2.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{-# LANGUAGE TemplateHaskell #-}

import Language.Haskell.TH
import Language.Haskell.TH.Syntax

listMembers :: Q [Con]
listMembers = do
info <- reify (mkName "Language.Haskell.TH.Syntax")
case info of
TyConI (DataD _ _ _ _ constructors _) -> return constructors
_ -> fail "Invalid type"

main :: IO ()
main = do
members <- runQ listMembers
putStrLn "Members:"
mapM_ (putStrLn . pprint) members
Binary file added 2023/06/26/test2.o
Binary file not shown.
25 changes: 25 additions & 0 deletions 2023/06/26/test3.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{-# LANGUAGE TemplateHaskell #-}

module THExample where

import Language.Haskell.TH
import Language.Haskell.TH.Syntax

listMembers :: Q [Con]
listMembers = do
info <- reify (mkName "Language.Haskell.TH.Syntax")
case info of
TyConI (DataD _ _ _ _ constructors _) -> return constructors
_ -> fail "Invalid type"
import Language.Haskell.TH

getMembers :: Q [Dec] -> Q [Dec]
getMembers qDecs = qDecs

doTheThing :: Q [Dec] -> Q [Dec]
doTheThing = getMembers

main :: IO ()
main = do
let constructors = $(doTheThing [d| data Color = Red |])
mapM_ (putStrLn . pprint) constructors
12 changes: 12 additions & 0 deletions 2023/06/26/test4.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Language.Haskell.TH

getMembers :: Q [Dec] -> Q [Dec]
getMembers qDecs = qDecs

doTheThing :: Q [Dec] -> Q [Dec]
doTheThing = getMembers

main :: IO ()
main = do
let constructors = $(doTheThing [d| data Color = Red |])
mapM_ (putStrLn . pprint) constructors
18 changes: 18 additions & 0 deletions 2023/06/26/test5.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{-# LANGUAGE TemplateHaskell #-}

import Language.Haskell.TH

getMembers :: Q [Dec] -> Q [Dec]
getMembers qDecs = qDecs
listMembers :: Q a -> Q [Con]
listMembers continuation = do
info <- reify (mkName "Language.Haskell.TH.Syntax"
)
case info of
TyConI (DataD _ _ _ _ constructors _) -> continu
ation >> return constructors
_ -> fail "Invalid type"
main :: IO ()
main = do
let constructors = listMembers
mapM_ (putStrLn . pprint) constructors
26 changes: 26 additions & 0 deletions 2023/06/26/test7.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{-# LANGUAGE TemplateHaskell #-}

module Main where

import Language.Haskell.TH

-- Helper function to list the names of functions in the current module
listFunctionNames :: Q [Name]
listFunctionNames = do
info <- reify ''Main -- Replace 'Main' with the actual module name
case info of
TyConI (DataD _ _ _ _ decs _) -> return $ extractFunctionNames decs
_ -> fail "Invalid module"

-- Extracts the names of functions from a list of declarations
extractFunctionNames :: [Dec] -> [Name]
extractFunctionNames = foldr extract [] where
extract (FunD name _) names = name : names
extract _ names = names

-- Print the names of functions in the current module
main :: IO ()
main = do
functionNames <- runQ listFunctionNames
putStrLn "Functions in the current module:"
mapM_ print functionNames
26 changes: 26 additions & 0 deletions 2023/06/26/test8.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{-# LANGUAGE TemplateHaskell #-}

module Main where

import Language.Haskell.TH

-- Helper function to list the names of functions in the current module
listFunctionNames :: Q [Name]
listFunctionNames = do
info <- reify (mkName "Main")
case info of
ModuleInfo _ declarations _ _ -> return $ extractFunctionNames declarations
_ -> fail "Invalid module"

-- Extracts the names of functions from a list of declarations
extractFunctionNames :: [Dec] -> [Name]
extractFunctionNames = foldr extract [] where
extract (FunD name _) names = name : names
extract _ names = names

-- Print the names of functions in the current module
main :: IO ()
main = do
functionNames <- runQ listFunctionNames
putStrLn "Functions in the current module:"
mapM_ print functionNames
3 changes: 3 additions & 0 deletions 2023/06/27/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tt:
ghc test24.hs
./test24
38 changes: 38 additions & 0 deletions 2023/06/27/good1.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

{-# LANGUAGE TemplateHaskell #-}

import Language.Haskell.TH

-- Foo data type
data Foo
= FooIdentifier Name
| FooVariable Name String
| FooComposed [Foo]

-- Convert Q Exp to Foo
qToFoo :: Q Exp -> Q Foo
qToFoo qexp = qexp >>= convertExp
where
convertExp (VarE name) = return (FooVariable name "")
convertExp (ConE name) = return (FooIdentifier name)
convertExp (AppE e1 e2) = do
foo1 <- qToFoo (return e1)
foo2 <- qToFoo (return e2)
return (FooComposed [foo1, foo2])
convertExp _ = error "Unsupported expression"

-- Convert Foo to String
fooToString :: Foo -> String
fooToString (FooIdentifier name) = show name
fooToString (FooVariable name value) = show name ++ " (" ++ value ++ ")"
fooToString (FooComposed foos) = concatMap fooToString foos

-- Example usage
main :: IO ()
main = do
let example = [| fooToString |]
foo <- runQ (qToFoo example)
putStrLn "Original Q expression:"
-- putStrLn (pprint example)
putStrLn "\nFoo conversion:"
putStrLn (fooToString foo)
14 changes: 14 additions & 0 deletions 2023/06/27/mod.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
data AnnLookup = AnnLookupModule Module | AnnLookupName Name
= ModuleAnnotation | TypeAnnotation Name | ValueAnnotation Name
= ModuleDoc | DeclDoc Name | ArgDoc Name Int | InstDoc Type
loc_module :: String,
type Module :: *
data Module = Module PkgName ModName
type ModuleInfo :: *
data ModuleInfo = ModuleInfo [Module]
qReifyModule :: Module -> m ModuleInfo
qReifyAnnotations, qReifyModule, qReifyConStrictness, qLocation,
nameModule :: Name -> Maybe String
reifyModule :: Module -> Q ModuleInfo
moduleAnnotation :: AnnTarget
thisModule :: Q Module
Loading

0 comments on commit e0feab0

Please sign in to comment.