kleene-type-0

Safe HaskellNone
LanguageHaskell2010

Kleene.Type.Examples.KleeneSH

Contents

Description

This module defines "type-safe" bindings to some of the UNIX shell tools.

We demonstrate the use of Kleene.Type (and KleenePlugin) to program in Haskell in completely structural way (i.e. non-nominal).

Disclaimer: the fact that we can doesn't mean that we should.

We may define self-proxy types instead of using K for flags. Then the usage will be more nice. However, we don't, to emphasise the point, as in this module we only use three types:

Example

{-# LANGUAGE DataKinds                #-}
{-# LANGUAGE OverloadedLabels         #-}
{-# OPTIONS_GHC -fplugin=KleenePlugin #-}
{-# OPTIONS_GHC -dcore-lint           #-}
module Main (main) where

import Kleene.Type.Examples.KleeneSH

main :: IO ()
main = do
    (( ls_, #l, ".", #h ))
    (( find_, #type, #f, "plugin", "src" ))

We get very close to the dynamic feeling, compare to:

(do
  (ls :l "." :h)
  (ls :type :f "plugin" "src"))
Synopsis

Commands

ls

ls_ :: REList LS -> IO () Source #

ls - list directory contents.

type LS = S (V FilePath \/ (Flag "l" \/ Flag "h")) Source #

find

find_ :: REList FIND -> IO () Source #

find - search for files in a directory hierarchy

type FIND' = V FilePath \/ ((Flag "name" <> V FilePath) \/ (Flag "type" <> TYPES)) Source #

type TYPES = Flag "d" \/ Flag "f" Source #

true

true_ :: REList TRUE -> IO () Source #

true - do nothing, successfully

type TRUE = T Source #

Implementation

command Source #

Arguments

:: REInductionC ToArg re 
=> FilePath

executable

-> REList re

arguments

-> IO () 

This is blunt command, we don't really need regular expression here as we quite simplfy flatten the the HList.

See find_ for more sophisticated example.

type Flag s = V (Key s) Source #

class ToArg a where Source #

Convert a to String cli-argument.

Methods

toArg :: a -> Either String String Source #

Instances
c ~ Char => ToArg [c] Source #

String is "good" argument, this is also FilePath instance.

Instance details

Defined in Kleene.Type.Examples.KleeneSH

Methods

toArg :: [c] -> Either String String Source #

KnownSymbol s => ToArg (Key s) Source #

Prepends the - character.

Instance details

Defined in Kleene.Type.Examples.KleeneSH

Re-exports