Anyone want to guess how many errors this code generates:
{-# LANGUAGE DerivingVia #-}
module T where
newtype OrdList1 a = OrdList1 [a]
deriving (Functor, Foldable, Traversable) via []
newtype OrdList2 a = OrdList2 [a]
deriving (Functor, Foldable, Traversable) via Maybe
The GitHub repo of the #haskellbasement and foundation packages was just archived, while it currently has 3764 indirect reverse dependencies including cryptonite, pandoc, and accelerate. I don't know why and I don't know what will happen now, but I am concerned.
@mangoiv@jaror I don't really see the problem? To my knowledge, Vincent has not really done any active Haskell work in quite a while, nor should anyone be forced to. Isn't it more honest to archive the repositories to reflect that state properly than to continue providing some illusion that these are active libraries? People can still use the code and fork / revive. Isn't this how open-source projects are supposed to work?
Also, I'm concerned that this goes unnoticed. Hackage does not currently show maintenance status very well, so people might think these packages are still suitable to use in new projects.
Brzozowski derivatives are neat, but good old denotational semantics of regular expressions can be very elegant too:
data RE = Empty | Eps | Ch Char | App RE RE | Alt RE RE | Star RE
foldRE :: p -> p -> (Char -> p) -> (p -> p -> p) -> (p -> p -> p) -> (p -> p) -> RE -> p
foldRE emp eps ch app alt star = go where
go = case
Empty -> emp
Eps -> eps
Ch c -> ch c
App p q -> app (go p) (go q)
Alt p q -> alt (go p) (go q)
Star p -> star (go p)
recognise :: RE -> String -> [String]
recognise =
foldRE (pure empty) pure (c -> case x : xs | c == x -> [xs]; _ -> [])
(>=>) (liftA2 (<|>)) (p -> fix (t -> liftA2 (<|>) pure (p >=> t)))
@mangoiv perhaps it is slightly easier to read like this?
data RE = Empty | Eps | Ch Char | App RE RE | Alt RE RE | Star RE
data REalg a = REalg
{ emp :: a
, eps :: a
, ch :: Char -> a
, app :: a -> a -> a
, alt :: a -> a -> a
, star :: a -> a
}
foldRE :: REalg a -> RE -> a
foldRE alg = go where
go = case
Empty -> emp alg
Eps -> eps alg
Ch c -> ch alg c
App p q -> app alg (go p) (go q)
Alt p q -> alt alg (go p) (go q)
Star p -> star alg (go p)
recognise :: RE -> StateT String [] ()
recognise = foldRE REalg
{ emp = empty
, eps = pure ()
, ch = c -> StateT (case x : xs | c == x -> [((), xs)]; _ -> [])
, app = (*>)
, alt = (<|>)
, star = p -> fix (t -> p *> t <|> pure ())
}
fresh :: FDState s c -> (Int, FDState s c)
fresh = id &&& id
>>> first (^. nextId)
>>> ((i, s) -> (i, s & alive %~ Set.insert i))
>>> second (nextId %~ (+ 1))
fresh :: FDState s c -> (Int, FDState s c)
fresh s@FDState {_nextId = i, _alive = as} =
(i, s {_nextId = i + 1, _alive = Set.insert i as})
Hangman.hs:46:32: error:
* Couldn't match type '[Char]' with 'Char'
Expected type: Char
Actual type: String
* In the first argument of 'makeGuess', namely 'letterInput'
In the first argument of 'gameLoop', namely
'(makeGuess letterInput gs)'
In the expression: gameLoop (makeGuess letterInput gs)
|
46 | else gameLoop (makeGuess letterInput gs)
| ^^^^^^^^^^^
Elm-style:
-- Type mismatch ---------------------------------------------------- Hangman.hs
46 | else gameLoop (makeGuess letterInput gs)
^^^^^^^^^^^
Couldn't match type '[Char]' with 'Char'
Actual type:
String
Expected type:
Char
I finally found a decent definition of free alternatives:
newtype Free f a = Free { alts :: [Free' f a] } deriving Functor
instance Applicative (Free f) where
pure = Free . pure . Pure
Free ps <*> q0 = asum $ map (`apL` q0) ps where
apL (Pure f) q = f <$> q
apL (Free' x p) q = Free $ pure $ Free' x $ flip <$> p <*> q
instance Alternative (Free f) where
empty = Free empty
Free ps <|> Free qs = Free (ps <|> qs)
data Free' f a = Pure a | forall x. Free' (f x) (Free f (x -> a))
deriving instance Functor (Free' f)
Exercise: why did I not write an instance Applicative (Free' f) and used deriving (Functor, Applicative, Alternative) via Compose [] (Free' f) to get the instances for Free?