packages feed

tilia-0.2.0.0: corpora/vendored/comment/declaration/comment-after-a-keyword-that-begins-a-declaration-out.hs

{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE NamedDefaults #-}
{-# LANGUAGE PatternSynonyms #-}

module Loom.Shuttle where

import Data.String (IsString (..))

pattern Empty :: -- the empty bobbin
  Bobbin
pattern Empty = Bobbin 0 -- one turn

pattern
  -- a full bobbin
  Full ::
  Bobbin
pattern
  -- as many turns as it holds
  Full = Bobbin 64

default IsString -- threads are named by strings
  ( String
  )

class Wound a where
  turns :: a -> Int
  default turns :: -- counted one at a time
    Show a => a -> Int
  turns = length . show

foreign import ccall "spin" -- the motor
  spin :: Int -> IO ()

foreign export ccall -- reported to the controller
  reel :: Int -> IO ()

foreign import
  -- blocks until the shuttle stops
  ccall unsafe "halt"
  halt :: IO ()

reel :: Int -> IO ()
reel = spin

wind :: Int %1 -> Int
wind n =
  let %1 m = n -- moved, not copied
   in m
{-# INLINE -- small enough
  wind
  #-}

newtype Bobbin = Bobbin Int