close
close

Announcing NeoHaskell v0.2.0: Bringing Elm-Inspired Architecture to CLI Applications

Announcing NeoHaskell v0.2.0: Bringing Elm-Inspired Architecture to CLI Applications

We are excited to announce the release of NeoHaskell v0.2.0! This release marks an important milestone in our journey to create a more accessible and powerful Haskell-based language. With this release, we are introducing a basic scaffolding for CLI applications inspired by the Elm architecture, as well as substantial improvements to our core library.

Elm-inspired CLI architecture

One of the most exciting features of version 0.2.0 is the introduction of an Elm-inspired event source architecture for building CLI applications. This approach brings the clarity and maintainability of Elm’s design to the world of command-line tools.

This architecture allows developers to build CLI applications with a clear separation of concerns, making it easier to reason about application state and user interactions.

Let’s see an example of creating a simple CLI application:

module SimpleTodo (main) where

import Core
import Command qualified
import Platform qualified

type Model =
  Record
    '( "todos" := Array Text,
       "currentInput" := Text
     )

data Message
  = AddTodo
  | UpdateInput Text
  | RemoveTodo Int
  | NoOp
  deriving (Show)

init :: (Model, Command Message)
init =
  let initialModel =
        ANON
          { todos = (),
            currentInput = ""
          }
  in (initialModel, Command.none)

update :: Message -> Model -> (Model, Command Message)
update message model =
  case message of
    AddTodo ->
      if Text.isEmpty model.currentInput
        then (model, Command.none)
        else
          ( model
              { todos = Array.push model.currentInput model.todos,
                currentInput = ""
              },
            Command.none
          )
    UpdateInput newInput ->
      (model {currentInput = newInput}, Command.none)
    RemoveTodo index ->
      ( model {todos = Array.removeAt index model.todos},
        Command.none
      )
    NoOp ->
      (model, Command.none)

view :: Model -> Text
view model = do
  let todoList = Text.joinWith "\n" model.todos
  let header = "Todo List:\n"
  let footer = "\nCurrent input: " ++ model.currentInput
  header ++ todoList ++ footer

main :: IO ()
main = Platform.init (ANON {init = init, view = view, update = update})
Enter full screen mode

Exit full screen mode

This example illustrates the key components of elm-inspired architecture:

  1. Model:Represents the state of the application
  2. Message: Defines the possible events in the application
  3. init: Configures the initial model and controls
  4. update: Manages state transitions based on messages
  5. view: Renders the current state as text
  6. main: Initializes the application using Platform module

Extended Base Library

We have significantly improved our core library to provide more powerful tools for NeoHaskell developers:

  • New concurrency primitives: Channel, VarAnd ConcurrentVar
  • AsyncIO asynchronous operations management module
  • Extended Array module with useful functions like flatMap And forEach
  • Version module for analysis and work with semantic versions
  • THE Unknown type to handle dynamic typing scenarios
  • A Record module for working with extensible records
  • New Json And Yaml modules for data serialization
  • A OptionsParser module to simplify CLI argument parsing
  • A Console module with built-in debugging capabilities

Attribute System Improvements

We’ve reorganized and extended our trait system to provide a more coherent and powerful set of abstractions:

  • Improved Appendable, ApplicableAnd Combinable features
  • A new ToText trait for consistent string conversion between types

To be involved

We can’t wait to see what the community creates with NeoHaskell v0.2.0! Here’s how you can get started:

  1. Check out our GitHub repository for the latest code
  2. Join our Discord community to discuss ideas and get help
  3. Try to create a small CLI application and share your experience

Your feedback and contributions are essential to continue evolving NeoHaskell. Let’s work together to create a more accessible and powerful development experience!

Happy coding!

pseudo