<commit_before>module CLDExample where

import Compile0
import GL

q, p, m :: Num a => a
q = 0
p = 1
m = -1

relation :: Int -> GCM (Port Int, Port Int)
relation s = do
  pi <- createPort
  po <- createPort

  component $ do
    i <- value pi
    o <- value po
    assert $    (i === q) ==>    (o === q)
    assert $ nt (i === q) ==> nt (o === negate (lit s * i))

  return (pi, po)

cldNode :: GCM (Port Int)
cldNode = do
  p <- createPort
  component $
    assert  $ val p `inRange` (-1, 1)
  return p

example :: GCM ()
example = do
  a <- cldNode 
  b <- cldNode

  linkBy (relation p) a b

  set a p

  output a "a"
  output b "b"<commit_msg>Made CLD example load with new internal structure<commit_after>module CLDExample where

import Compile0(runGCM)
import GCM     (GCM, component, output, Port, createPort, linkBy, value, set)
import CP      (assert, lit, nt, (===), (==>), inRange)

-- Labels for the relations (arrows) in a Causal Loop Diagram
q, p, m :: Num a => a
q =  0  -- ? = question mark
p =  1  -- + = plus
m = -1  -- - = minus

relation :: Int -> GCM (Port Int, Port Int)
relation s = do
  pi <- createPort
  po <- createPort

  component $ do
    i <- value pi
    o <- value po
    assert $    (i === q) ==>    (o === q)
    assert $ nt (i === q) ==> nt (o === negate (lit s * i))

  return (pi, po)

cldNode :: GCM (Port Int)
cldNode = do
  p <- createPort
  component $ do
    pv <- value p
    assert  $ pv `inRange` (-1, 1)
  return p

example :: GCM ()
example = do
  a <- cldNode
  b <- cldNode

  linkBy (relation p) a b

  set a p

  output a "a"
  output b "b"
{'fraction_non_alphanumeric': 0.14698492462311558, 'fraction_numerical': 0.007537688442211055, 'mean_word_length': 2.2845360824742267, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '199358', 'n_tokens_mistral': 632, 'n_tokens_neox': 594, 'n_words': 233}