packages feed

tilia-0.2.0.0: corpora/vendored/comment/declaration/comments-next-to-keywords-out'.hs

{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE TransformListComp #-}

module {- the controller of a loom -} Loom.Control where

import GHC.Exts (groupWith)

data Command a where
    Start :: Command ()
    Speed :: Command Int

type role -- set by the controller only
    Shed
        nominal

type
    -- the threads may not be coerced
    role
    Heddle
        nominal

class Pedal p where
    press :: p -> Int
    release :: p -> Int
    {-# MINIMAL
        -- either one will do
        press | release #-}

pattern Fast :: Int
pattern Fast <- 120
    -- the fastest the loom runs
    where
        Fast = 120

describe :: Command a -> String
describe = \case -- one word for each
    Start -> "start"
    Speed -> "speed"

compare' :: Int -> Int -> Int
compare' = \cases -- by speed alone
    a b | a < b -> -1
    _ _ -> 1

pace :: Int -> String
pace n =
    if -- from the slowest
        | n < 60 -> "slow"
        | otherwise -> "fast"

grouped :: [Int] -> [[Int]]
grouped xs =
    [ x
    | x <- xs
      -- by speed
    , then group by
        x
      using
        groupWith
    ]

newtype Shed a = Shed a

newtype Heddle a = Heddle a