User Tools

Site Tools


codesnippets:minimalcompletedefinition

Annotation for a minimal complete definition

Format:

{-# MINIMAL function1 | function2 #-}

Minimal pragmas are boolean expressions. For instance, with | as logical OR, either definition of the above functions must be defined. Comma indicates logical AND where both definitions must be defined.

See also: External Link

Example

{-# LANGUAGE GADTs #-}

module Main where

main :: IO ()
main = 
        do
                print x

data MayBe' a 
        where
                Just' :: Eq a => a -> MayBe' a
                Nothing' :: Eq a => MayBe' a

class Eq' a where
    (===) :: a -> a -> Bool
    (/==) :: a -> a -> Bool
    (===) x y = not (x /== y)
    x /== y = not (x === y)
    {-# MINIMAL (===) | (/==) #-}


instance Eq' (MayBe' a)
        where
                -- (===) (Just' x) (Just' y) = x == y
                -- (/==) (Just' x) (Just' y) = x /= y

x = (Just' 2) === (Just' 3)

…provides the warning…

app\Main.hs:23:10: warning: [-Wmissing-methods]
    * No explicit implementation for
        either `===' or `/=='
    * In the instance declaration for `Eq' (MayBe' a)'
   |
23 | instance Eq' (MayBe' a)
   | 

…whereas this code…

instance Eq' (MayBe' a)
        where
                -- (===) (Just' x) (Just' y) = x == y
                (/==) (Just' x) (Just' y) = x /= y

x = (Just' 2) === (Just' 3)

…leads to the following output:

False
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
You could leave a comment if you were logged in.
codesnippets/minimalcompletedefinition.txt · Last modified: by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki