The closest equivalent to a Prolog symbol or a Lisp symbol in Haskell

I am trying to write a simple program for manipulating expressions in the propositional calculus and would like to have good syntax for sentence variables (for example, 'Por something else).

Strings do the job, but the syntax is misleading in this context, and they allow inappropriate operations such as ++.

Syntactically, I would like to write something that does not look โ€œlookโ€ visually (something seems 'Pto be in order, though). Regarding the supported operations, I would like to determine if the two characters are equal and convert them to a string corresponding to their name with show. I would also like these things to be open (ADTs with only null constructors are basically similar to characters, but require all options to be declared in advance).

Here's an example of a toy that uses strings that look like a character.

type Var = String

data Proposition =
    Primitive Var |
    Negated Proposition |
    Implication Proposition Proposition

instance Show Proposition where
    show (Primitive p) = p
    show (Negated n) = "!" ++ show n
    show (Implication ant cons) = 
        "(" ++ show ant ++ "->" ++ show cons ++ ")"

main = putStrLn $ show $ Implication (Primitive "A") (Primitive "B")
+4
source share
1 answer

Usually, as is done in Haskell, parameterization is by character type. Thus, your example will be as follows:

data Proposition a = 
    Primitive a |
    Negated (Proposition a) |
    Implication (Proposition a) (Proposition a)

, . LISP: , , , , , , , . , Functor Monad.

(=<<) :: (a        ->      Proposition b)      -> Proposition a -> Proposition b
          ^                ^^^^^^^^^^^^^          ^^^^^^^^^^^^^        
substitute each free var   with an expression   in this expression

:

implyOpen :: Proposition a -> Proposition b -> Proposition (Either a b)
implyOpen p q = Implication (Left <$> p) (Right <$> q)

.

data Proposition a = 
    ... |
    ForAll (Proposition (Maybe a))

" " - Primitive Nothing - , . , , , .

bound - ( ).

+7

Source: https://habr.com/ru/post/1676009/


All Articles