News for hackers. Stuff that matters.
Re:The algebra and calculus of algebraic data types by matt-noonan on Saturday September 08, 2018 @09:57PM (#17943880)
The "should be able to just return its argument" part is wrong; the types pretty clearly don't match, yeah? It is true that there is a unique function of type `Void -> a` for each `a`, but that isn't it.
Re:The algebra and calculus of algebraic data types by tpush on Sunday September 09, 2018 @06:26AM (#17945237)
When the Bottom type is included in a language it usually exhibits sub typing behavior. That can be expressed in Haskell, too:

  {-# LANGUAGE RankNTypes #-}

  type Bottom = forall a. a -- zero inhabitants

  f :: Bottom -> a
  f x = x

That passes the type checker just fine.
Re:The algebra and calculus of algebraic data types by joel_ms on Monday September 10, 2018 @01:49AM (#17949662)
> That passes the type checker just fine.

I think you are running into some weird haskellisms with your Bottom-type.

The normal way of defining that in haskell is using the "EmptyDataDecls" pragma, like this:

    {-# LANGUAGE EmptyDataDecls #-}

    data Empty 

    g :: Empty -> a
    g x = x 
Which doesn't pass the type checker.

(From a theoretic standpoint, I would have thought your Bottom was a essentially a type-level identity function..)

Re:The algebra and calculus of algebraic data types by tpush on Monday September 10, 2018 @05:58AM (#17950620)
Again, languages with a built in bottom usually have sub typing behavior that makes bottom a subtype of everything (so you can give a value of type bottom to everything).

'forall a. a' is just how you define the bottom type in System F, which Haskell is somewhat based on. As a type it describes that a term of that type can just conjure a value of any type out of thin air, which is obviously nonsense. That what makes it the bottom type.

The sub typing behavior associated with that is just the normal subsumption rule of polymorphic functions. The same reason why you can pass a function of type 'forall a. a -> a' to something expecting a function of type 'Int -> Int'. The types don't 'match' directly, but they do under the subsumption rule.

Re:The algebra and calculus of algebraic data types by joel_ms on Monday September 10, 2018 @08:42AM (#17951349)
Yeah, I just wanted to show that (GHC) haskell has a way of getting a type with "zero" inhabitants that actually gets caught by the type checker. (I say "zero" since of course my Empty-type above does contain non-terminating programs and (undefined :: a).)

With "forall a. a" I was coming from the persepctive of intuisionistic type theory where the usual parametric polymorphism just get subsumed by Π-types and universal quantification is usually represented with Π-types, so you would have:

         forall a.a       (Universal Quantification)
    <==> Π(a : Type) a    (Π-type)
    <==> (a : Type) -> a  (Agda-notation)
     ==> a -> a           (Π-type as regular function type)
where Type represents any type. That's what I meant by "type-level identity function".
Re:The algebra and calculus of algebraic data types by matt-noonan on Monday September 10, 2018 @09:38AM (#17951685)
Interesting, thanks! I hadn't considered using "forall a. a" as the bottom type, but it makes sense.