<commit_before>{-# LANGUAGE BangPatterns, ScopedTypeVariables #-}

-----------------------------------------------------------------------------
-- |
-- Copyright   : (C) 2014 <NAME>
-- License     : BSD3
--
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : experimental
-- Portability : portable
----------------------------------------------------------------------------

module Photon.Core.Loader (
    -- * Loading resources
    loadJSON
  , load 
    -- * Loaders
  , loadMesh
  , loadMaterial
  , loadLight
  ) where

import Control.Exception ( IOException, catch )
import Control.Monad ( (>=>), MonadPlus(..) )
import Control.Monad.Trans ( MonadIO, liftIO )
import Data.ByteString.Lazy as B ( readFile )
import Data.Aeson
import Photon.Core.Effect
import Photon.Core.Light ( Light, LightSpawned )
import Photon.Core.Material ( Material, MaterialSpawned )
import Photon.Core.Mesh ( Mesh, MeshSpawned )
import Photon.Utils.Log
import Photon.Utils.TimePoint
import System.FilePath

rootPath :: FilePath
rootPath = "data"

class Load a e | a -> e where
  load :: (MonadIO m,MonadLogger m,MonadPlus m,Manageable a m,FromJSON a,Effect e m)
       => String
       -> m (Managed a)

instance Load Mesh MeshSpawned where
  load = loadMesh >=> spawn

instance Load Material MaterialSpawned where
  load = loadMaterial >=> spawn

instance Load Light LightSpawned where
  load = loadLight >=> spawn

loadJSON :: (MonadIO m,MonadLogger m,FromJSON a) => FilePath -> m (Either String a)<commit_msg>Update Loader.hs<commit_after>{-# LANGUAGE BangPatterns, ScopedTypeVariables #-}

-----------------------------------------------------------------------------
-- |
-- Copyright   : (C) 2014 <NAME>
-- License     : BSD3
--
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : experimental
-- Portability : portable
----------------------------------------------------------------------------

module Photon.Core.Loader (
    -- * Loading resources
    loadJSON
  , load 
    -- * Loaders
  , loadMesh
  , loadMaterial
  , loadLight
  ) where

import Control.Exception ( IOException, catch )
import Control.Monad ( MonadPlus(..) )
import Control.Monad.Trans ( MonadIO, liftIO )
import Data.ByteString.Lazy as B ( readFile )
import Data.Aeson
import Photon.Core.Light ( Light )
import Photon.Core.Material ( Material )
import Photon.Core.Mesh ( Mesh )
import Photon.Utils.Log
import Photon.Utils.TimePoint
import System.FilePath

rootPath :: FilePath
rootPath = "data"

class Load a where
  load :: (MonadIO m,MonadLogger m,MonadPlus m,FromJSON a)
       => String
       -> m (Managed a)

instance Load Mesh where
  load = loadMesh

instance Load Material where
  load = loadMaterial

instance Load Light where
  load = loadLight

loadJSON :: (MonadIO m,MonadLogger m,FromJSON a) => FilePath -> m (Either String a)
{'fraction_non_alphanumeric': 0.20756062767475036, 'fraction_numerical': 0.003566333808844508, 'mean_word_length': 2.2465277777777777, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 28, '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': '5970538', 'n_tokens_mistral': 828, 'n_tokens_neox': 815, 'n_words': 232}