<commit_before>module Main

{-

Copyright [2014] <NAME>

Licensed under the Apache License, Version 2.0 (the "License"); you
may not use this file except in compliance with the License.  You may
obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.  See the License for the specific language governing
permissions and limitations under the License.

-}

-- Data

data AmazonWebServices : a -> b -> Type where
  AWS : a -> b -> AmazonWebServices a b

data ElasticComputeCloud : a -> b -> Type where
  EC2 : a -> b -> ElasticComputeCloud a b

data SimpleDataBase : a -> b -> Type where
  SimpleDB : a -> b -> SimpleDataBase a b

data SimpleStorageService : a -> b -> Type where
  S3 : a -> b -> SimpleStorageService a b

-- Classes

class AmazonWebServicesAPI a b where
  aws : a -> IO (AmazonWebServices a b)

class ElasticComputeCloudAPI a b where
  ec2 : AmazonWebServices a b -> IO (ElasticComputeCloud a b)
  describeImages : ElasticComputeCloud a b -> IO b
  describeInstances : ElasticComputeCloud a b -> IO b

class SimpleDataBaseAPI a b where
  simpledb : AmazonWebServices a b -> IO (SimpleDataBase a b)
  listDomains : SimpleDataBase a b -> IO b

class SimpleStorageServiceAPI a b where
  s3 : AmazonWebServices a b -> IO (SimpleStorageService a b)
  listBuckets : SimpleStorageService a b -> IO b

-- JavaScript

data JavaScript : Type where
  JS : JavaScript

data Event : Type where
  Complete : Event
  Error : Event
  Success : Event

instance Show Event where
  show Complete = "complete"
  show Error = "error"
  show Success = "success"

on : Event -> (Ptr -> IO ()) -> Ptr -> IO (Ptr)
on e f j =
  mkForeign (FFun "%0.on(%1,%2)"
             [ FPtr
             , FString
             , FFunction (FAny Ptr) (FAny (IO ()))
             ] FPtr) j (show e) f >>= return

send : Ptr -> IO ()
send j = mkForeign (FFun ("%0.send()") [FPtr] FUnit) j

log : Ptr -> IO ()
log j = mkForeign (FFun ("console.log(%0)") [FPtr] FUnit) j

logHandler : Ptr -> IO (Ptr)<commit_msg>add some sugar<commit_after>module Main

{-

Copyright [2014] <NAME>

Licensed under the Apache License, Version 2.0 (the "License"); you
may not use this file except in compliance with the License.  You may
obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.  See the License for the specific language governing
permissions and limitations under the License.

-}

-- Data

data AmazonWebServices : a -> b -> Type where
  AWS : a -> b -> AmazonWebServices a b

data ElasticComputeCloud : a -> b -> Type where
  EC2 : a -> b -> ElasticComputeCloud a b

data SimpleDataBase : a -> b -> Type where
  SimpleDB : a -> b -> SimpleDataBase a b

data SimpleStorageService : a -> b -> Type where
  S3 : a -> b -> SimpleStorageService a b

-- Classes

class AmazonWebServicesAPI a b where
  aws : a -> IO (AmazonWebServices a b)

class ElasticComputeCloudAPI a b where
  ec2 : AmazonWebServices a b -> IO (ElasticComputeCloud a b)
  describeImages : ElasticComputeCloud a b -> IO b
  describeInstances : ElasticComputeCloud a b -> IO b

class SimpleDataBaseAPI a b where
  simpledb : AmazonWebServices a b -> IO (SimpleDataBase a b)
  listDomains : SimpleDataBase a b -> IO b

class SimpleStorageServiceAPI a b where
  s3 : AmazonWebServices a b -> IO (SimpleStorageService a b)
  listBuckets : SimpleStorageService a b -> IO b

-- JavaScript

data JavaScript : Type where
  JS : JavaScript

data Event : Type where
  Complete : Event
  Error : Event
  Success : Event

instance Show Event where
  show Complete = "complete"
  show Error = "error"
  show Success = "success"

infixr 7 ~>
(~>) : FTy -> FTy -> FTy
(~>) a b = FFunction a b

on : Event -> (Ptr -> IO ()) -> Ptr -> IO (Ptr)
on e f j =
  mkForeign (FFun "%0.on(%1,%2)"
             [ FPtr
             , FString
             , FAny Ptr ~> FAny (IO ())
             ] FPtr) j (show e) f >>= return

send : Ptr -> IO ()
send j = mkForeign (FFun ("%0.send()") [FPtr] FUnit) j

log : Ptr -> IO ()
log j = mkForeign (FFun ("console.log(%0)") [FPtr] FUnit) j

logHandler : Ptr -> IO (Ptr)
{'fraction_non_alphanumeric': 0.09823621344050011, 'fraction_numerical': 0.007814244250948872, 'mean_word_length': 3.0764331210191083, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '839272', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1386, 'n_words': 590}