instance infixFoldable :: Foldable Tree where
foldl f acc Leaf = acc
foldl f acc (Branch left node right) = foldl f (f (foldl f acc left) node) right
foldr = foldrDefault
foldMap = foldMapDefaultL
Any idea what I am doing wrong?
Nat m n = Nat (m ~> n)
but not with a record NatR m n = Nat { nat :: (m ~> n) }
use :: forall m n. Nat m n -> m Unit -> n Unit
use (Nat nat) = nat
useR :: forall m n. NatR m n -> m Unit -> n Unit
useR (NatR { nat }) = nat -- Error!
I get an error with useR
: Could not match type
a2
with type
Unit
while trying to match type m0 a2
with type m0 Unit
while checking that expression nat
has type m0 Unit -> n1 Unit
in value declaration useR
where n1 is a rigid type variable
bound at (line 0, column 0 - line 0, column 0)
m0 is a rigid type variable
bound at (line 0, column 0 - line 0, column 0)
a2 is a rigid type variable
bound at (line 17, column 34 - line 17, column 54)
@Ebmtranceboy Thanks, neat trick! I had to extend my minimal example because unfortunately, in my case it still didn't work. https://try.purescript.org/?gist=c544c34971cecfd61528fa06c996460b
data Nat m n = Nat (m ~> n)
data NatR m n = NatR { nat :: (m ~> n) }
morphS :: forall m n. Monad m => Monad n => (m ~> n) -> m Unit -> n Unit
morphS t fm = t fm
-- useR :: forall m n. Monad m => Monad n => NatR m n -> m Unit -> n Unit
-- useR (NatR { nat }) x = morphS nat x -- Error!
-- Error: Could not match type a4 with a1
-- a4 rigid type variable bound at line 17, column 34-54...
-- Stays at line 17 even if I move the code around.
-- Actually it's also the same location in my local code base... Wat?
useR' :: forall m n. Monad m => Monad n => NatR m n -> m Unit -> n Unit
useR' (NatR h) x = morphS h.nat x -- Works
useR'' :: forall m n. Monad m => Monad n => NatR m n -> m Unit -> n Unit
useR'' (NatR h) = morphS h.nat -- Pointfree also works
There's also some added strangeness going on with the code location reported by the type checker... Should some of this be documented as gotchas somewhere so that they're googleable?
morphS
with identity
in the useR
definition but you probably have something else in mind :) I advise you to ask on the functional programming Slack, channel #purescript or #purescript-beginners. They're quite crowded
Nothing
from Data.Maybe
I am getting an error as shown above
(..)
asks to not only import the type, but also the type constructors (Just
and Nothing
)
I have a type system question.
I can express head as a natural transformation like so:
head' ∷ List ~> Maybe
head' = head
My intuition is that join
is also a natural transformation of the type forall m. m m ~> m
But if the kind of m :: Type -> Type
then m m
won't compile because the kind of the type argument to the outer m is type -> type
and it expects the kind type
join' ∷ forall (m :: Type → Type) . Bind m ⇒ m m ~> m
join' = join
join' ∷ forall (m :: Type → Type) . Bind m ⇒ m m ~> m
^
Could not match kind
Type
with kind
Type -> Type
I also tried using a type lambda there to get the the type of the inner m to be correct
43 join'' ∷ forall (m :: Type → Type) . Bind m ⇒ (∀ a. a → m (m a)) ~> m
^^^^^^^^^^^^^^^^
Could not match kind
Type -> Type
with kind
Type
Which results in a different type error. Which I am very confused by, the compiler seems to be expect the underlined section to have the kind type
but I would expect that it should be type -> type
because it's on the left of ~>
Does anyone know how I can express join
as NaturalTransformation
or am I just completely lost.
module Main where
import Data.Array
import Data.Array.ST
import Effect.Ref
import Prelude
import Control.Monad.ST.Internal
import Control.Monad.ST (run, for)
import Control.Monad.ST.Ref as Ref
import Effect (Effect, forE)
import Effect.Class.Console (log, logShow)
import Data.Maybe (Maybe(..), fromMaybe)
import Partial.Unsafe (unsafePartial)
main :: Effect Unit
main = void $ unsafePartial do
let nodes = [
[-100.0, -100.0, -100.0],
[-100.0, -100.0, 100.0],
[-100.0, 100.0, -100.0],
[-100.0, 100.0, 100.0],
[ 100.0, -100.0, -100.0],
[ 100.0, -100.0, 100.0],
[ 100.0, 100.0, -100.0],
[ 100.0, 100.0, 100.0]
]
ref <- empty
void $ forE 0 8 $ \i -> do
let xx = (nodes !! i)
let yy = fromMaybe [] xx
void $ push yy ref
log "x"
push yy ref
it's throwing
Could not match type
ST t1
with type
Effect
while trying to match type t0 Unit
with type Effect Unit
while checking that expression (apply void) ((push yy) ref)
has type Effect Unit
in value declaration main
where t0 is an unknown type
t1 is an unknown type