Views
No views yet
1mlx_lm.generate --model release/Qwen3-Next-80B-A3B-Instruct-qx64-mlx --max-tokens 20000 \
2--prompt "If you were to write an Agnostic Agent as a CLI for a user to interact with Ollama API, and want to use FP, what language would you prefer"Haskell
IO and monads — perfect for modeling an agent that:StateT, ReaderT)1data Model = Model { name :: String, description :: Maybe String }
2
3data Request = Request
4 { model :: Model
5 , prompt :: String
6 , stream :: Bool
7 , options :: Maybe Options
8 }
9
10data Response = Response
11 { completion :: String
12 , done :: Bool
13 , context :: [Int]
14 }
15
16data Error = ApiError String | JsonParseError String | TimeoutErrorhttp-client — robust, streaming, async-capableaeson — fast, composable JSON encoding/decodingswagger (optional) — if you want to generate clients from OpenAPI specs/api/generate, /api/tags, etc.optparse-applicative1main :: IO ()
2main = do
3 opts <- execParser optsParser
4 result <- runAgent opts
5 either (putStrLn . show) putStrLn resultrunAgent :: AgentConfig -> IO AgentResult) is pure and testable.Backend module — no logic changes.stream: true). Haskell’s lazy evaluation and conduit/pipes libraries make streaming response processing elegant and memory-safe.stack build --executable produces a single static binary — perfect for CLI tools.| Language | Pros | Cons |
|---|---|---|
| Rust | Fast, safe, great CLI tools (clap) | Not purely functional; FP possible but not enforced |
| Elm | Pure FP, great for UI | No CLI/HTTP support; not suited for backend/CLI |
| PureScript | Haskell-like, compiles to JS | Weak CLI tooling; Ollama API needs HTTP, not browser |
| F# | Great FP + .NET | Less mature for CLI/HTTP; ecosystem smaller than Haskell |
| Scala | FP + JVM | Heavy, slow startup, overkill for CLI |
| Clojure | Functional, Lisp | Dynamic typing, less type safety; harder to reason about API contracts |
1main :: IO ()
2main = do
3 input <- getLine
4 let request = buildRequest "llama3" input
5 response <- sendToOllama request
6 putStrLn $ formatResponse responsebuildRequest — pure functionsendToOllama — IO ResponseformatResponse — pure functionbuildRequest and formatResponse without touching the network.Haskell is the ideal language to build an Agnostic Agent CLI for Ollama using Functional Programming because it:
- Enforces purity and immutability
- Provides strong typing for API contracts
- Offers excellent tooling for HTTP, JSON, and CLI
- Enables true separation of concerns
- Produces fast, reliable, testable binaries
freer-simple or extensible-effects — but even vanilla Haskell is more than sufficient.1Prompt: 42 tokens, 163.629 tokens-per-sec
2Generation: 1125 tokens, 54.763 tokens-per-sec
3Peak memory: 53.458 GBpip install mlx-lm1from mlx_lm import load, generate
2
3model, tokenizer = load("Qwen3-Next-80B-A3B-Instruct-qx64-mlx")
4
5prompt = "hello"
6
7if tokenizer.chat_template is not None:
8 messages = [{"role": "user", "content": prompt}]
9 prompt = tokenizer.apply_chat_template(
10 messages, add_generation_prompt=True
11 )
12
13response = generate(model, tokenizer, prompt=prompt, verbose=True)