Compare commits

..

2 Commits

Author SHA1 Message Date
Enrico Lumetti a8ec2f9f21 Beginning haskell code 2024-08-14 17:59:11 +02:00
Enrico Lumetti 3265b7bbb0 Move racket code to racket/ 2024-08-14 17:58:09 +02:00
38 changed files with 86 additions and 9 deletions

19
.kakrc
View File

@ -1,9 +1,10 @@
hook -once -group eoc global KakBegin .* %{ set global makecmd 'cabal build'
repl-buffer-new racket -i #hook -once -group eoc global KakBegin .* %{
repl-buffer-send-text "(require xrepl) # repl-buffer-new racket -i
" # repl-buffer-send-text "(require xrepl)
%} #"
#%}
define-command xrepl-enter %{ #
repl-buffer-send-text ",en %val{buffile}" #define-command xrepl-enter %{
} # repl-buffer-send-text ",en %val{buffile}"
#}

46
Main.hs Normal file
View File

@ -0,0 +1,46 @@
module Main where
import Data.Aeson (FromJSON, parseJSON, withObject, withText, (.:), decode)
data Program = Program { programFns :: [Function] }
deriving (Show)
data Function = Function {
functionName :: String,
returnType :: Maybe Type,
functionArgs :: [FunctionArg]
} deriving (Show)
data Type = Int | Bool
deriving (Show)
data FunctionArg = FunctionArg {
argName :: String,
argType :: Type
} deriving (Show)
instance FromJSON Program where
parseJSON = withObject "Program" $ \v -> Program
<$> v .: "functions"
instance FromJSON Function where
parseJSON = withObject "Function" $ \v -> Function
<$> v .: "name"
<*> v .: "type"
<*> v .: "args"
instance FromJSON FunctionArg where
parseJSON = withObject "FunctionArg" $ \v -> FunctionArg
<$> v .: "name"
<*> v .: "type"
instance FromJSON Type where
parseJSON = withText "Type" $ \v ->
case v of
"int" -> return Int
"bool" -> return Bool
_ -> fail "wrong type"
main :: IO ()
main = do
putStrLn $ show (decode "int" :: Maybe Type)

2
Setup.hs Normal file
View File

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

28
eoc.cabal Normal file
View File

@ -0,0 +1,28 @@
cabal-version: >=1.10
-- Initial package description 'eoc.cabal' generated by 'cabal init'. For
-- further documentation, see http://haskell.org/cabal/users-guide/
name: eoc
version: 0.1.0.0
-- synopsis:
-- description:
-- bug-reports:
-- license:
license-file: LICENSE
author: Enrico Lumetti
maintainer: enrico.lumetti@gmail.com
-- copyright:
-- category:
build-type: Simple
extra-source-files: README.md
executable eoc
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends:
base >=4.13 && <4.14,
aeson >= 2.2
-- hs-source-dirs:
default-language: Haskell2010
default-extensions: DeriveGeneric, OverloadedStrings