Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,323
    • Issues 4,323
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 385
    • Merge Requests 385
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #13920

Closed
Open
Opened Jul 04, 2017 by zaoqi@trac-zaoqi

自動選擇實例

https://github.com/zaoqi/U.hs/blob/master/Data/U.hs:

--Copyright (C) 2017  Zaoqi

--This program is free software: you can redistribute it and/or modify
--it under the terms of the GNU Affero General Public License as published
--by the Free Software Foundation, either version 3 of the License, or
--(at your option) any later version.

--This program is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--GNU Affero General Public License for more details.

--You should have received a copy of the GNU Affero General Public License
--along with this program.  If not, see <http://www.gnu.org/licenses/>.
{-# LANGUAGE DataKinds, TypeOperators, KindSignatures, GADTs, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, AllowAmbiguousTypes,
UndecidableInstances, IncoherentInstances, NoMonomorphismRestriction #-}
module Data.U (
    U(),
    t,
    u
    ) where

data U :: [*] -> * where
    UOne :: x -> U (x : xs)
    USucc :: U xs -> U (x : xs)

class T1 a b where
    t1 :: (U a) -> (U b)
instance T1 a a where
    t1 = id
instance T1 xs (x : xs) where
    t1 = USucc
instance T1 (x : y : xs) (y : x : xs) where
    t1 (UOne x) = USucc (UOne x)
    t1 (USucc (UOne x)) = UOne x
    t1 (USucc (USucc xs)) = USucc (USucc xs)
instance T1 xs ys => T1 (x : xs) (x : ys) where
    t1 (UOne x) = UOne x
    t1 (USucc xs) = USucc (t1 xs)
t = t1 . t1 . t1 . t1 . t1 . t1 . t1 . t1

uone :: a -> U '[a]
uone = UOne
u x = t (uone x)

instance Show x => Show (U '[x]) where
    show (UOne x) = "(u " ++ showsPrec 11 x ")"
instance (Show x, Show (U xs)) => Show (U (x : xs)) where
    show (UOne x) = "(u " ++ showsPrec 11 x ")"
    show (USucc xs) = show xs
*Data.U> (u 'c') :: U [Int,Char]

<interactive>:12:2: error:
    • No instance for (T1 a30 '[Int, Char]) arising from a use of ‘u’
    • In the expression: (u 'c') :: U '[Int, Char]
      In an equation for ‘it’: it = (u 'c') :: U '[Int, Char]
*Data.U> t1 (uone 'c') :: U [Int,Char]
(u 'c')
Edited Mar 10, 2019 by Ben Gamari
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#13920