[Haskell-cafe] Mild confusion around type family

Nicholls, Mark nicholls.mark at vimn.com
Thu Jun 18 16:19:38 UTC 2015

Below is a very simple almost canonical natural number model.

I'm slightly confused by how type families work

Wikipedia says....

"Type families are a feature of some type systems<https://en.wikipedia.org/wiki/Type_system> that allow PARTIAL functions between types to be defined by pattern matching<https://en.wikipedia.org/wiki/Pattern_matching>"


> {-# LANGUAGE DataKinds #-}
> {-# LANGUAGE ExplicitForAll #-}
> {-# LANGUAGE FlexibleContexts #-}
> {-# LANGUAGE FlexibleInstances #-}
> {-# LANGUAGE GADTs #-}
> {-# LANGUAGE MultiParamTypeClasses #-}
> {-# LANGUAGE PolyKinds #-}
> {-# LANGUAGE StandaloneDeriving #-}
> {-# LANGUAGE TypeFamilies #-}
> {-# LANGUAGE TypeOperators #-}
> {-# LANGUAGE UndecidableInstances #-}
> {-# LANGUAGE ScopedTypeVariables #-}

lets do something simple

> data Z
> data S n

> type family Sub a b

> -- a - 0 == a
> type instance Sub a Z = a
> -- (a + 1) - (b + 1) == a - b
> type instance Sub (S a) (S b) = Sub a b

> oneMinusOne :: Z
> oneMinusOne = undefined :: Sub (S Z) (S Z)

I want this to be a type error!...but the above type family appears to not be partial...this IS defined...."Sub Z (S Z)" is a type! (I thought it wasn't)

> oneMinusTwo :: Sub Z (S Z)
> oneMinusTwo = undefined :: Sub (S Z) (S (S Z))


This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited.

While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data.

Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate measures to minimise these risks when e-mailing us.

MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks Europe.  MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc.  Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150618/ea802294/attachment.html>

More information about the Haskell-Cafe mailing list