[Haskell-cafe] Mild confusion around type family

Nicholls, Mark nicholls.mark at vimn.com
Fri Jun 19 14:14:57 UTC 2015


Ah ok...my mistake...

Lets do closed (below)....same problem.

Its not partial.....so how do we make it a type error?...."1 - 2" is not defined on the natural numbers (I'll have a go with datakinds....)


> {-# 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 where
> -- a - 0 == a
>   Sub a Z = a
> -- (a + 1) - (b + 1) == a - b
>   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!...

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





>-----Original Message-----
>From: Haskell-Cafe [mailto:haskell-cafe-bounces at haskell.org] On Behalf Of
>Adam Gundry
>Sent: 19 June 2015 2:20 PM
>To: haskell-cafe at haskell.org
>Subject: Re: [Haskell-cafe] Mild confusion around type family
>
>On 18/06/15 17:19, Nicholls, Mark wrote:
>>> data Z
>>> data S n
>>
>>> type family Sub a b
>>> type instance Sub a Z = a
>>> type instance Sub (S a) (S b) = Sub a b
>>
>> 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 is a slightly subtle point about type families. The type family application
>`Sub Z (S Z)` does not reduce, but neither is it an error.
>In this case, because Sub is an open type family, there is nothing to stop
>someone subsequently defining something like
>
>    type instance Sub Z (S b) = Z
>
>in another module.
>
>Type families are functional relations, not functions in the FP sense.
>
>See also the discussion here, about the corresponding situation for a closed
>type family: https://ghc.haskell.org/trac/ghc/ticket/9636
>
>Hope this helps,
>
>Adam
>
>--
>Adam Gundry, Haskell Consultant
>Well-Typed LLP, http://www.well-typed.com/
>_______________________________________________
>Haskell-Cafe mailing list
>Haskell-Cafe at haskell.org
>http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
CONFIDENTIALITY NOTICE

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.



More information about the Haskell-Cafe mailing list